@Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    mWeb = WowTalkWebServerIF.getInstance(this);
    mMomentWeb = MomentWebServerIF.getInstance(this);
    mDb = Database.open(this);

    handleCommand(intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
  }
예제 #2
0
파일: History.java 프로젝트: Kyrremann/HCT
  private void fillList() {
    db.open();
    historyTable = db.getTables();
    startManagingCursor(historyTable);

    String[] from = new String[] {Database.KEY_TITLE, Database.KEY_DATE};
    int[] to = new int[] {R.id.historyRow, R.id.historyRow2};

    SimpleCursorAdapter notes =
        new SimpleCursorAdapter(this, R.layout.notes_row, historyTable, from, to);
    setListAdapter(notes);
    db.close();
  }
예제 #3
0
  @Activate
  public void activate() {
    localNodeId = clusterService.getLocalNode().id();
    // load database configuration
    File databaseDefFile = new File(PARTITION_DEFINITION_FILE);
    log.info("Loading database definition: {}", databaseDefFile.getAbsolutePath());

    Map<String, Set<NodeInfo>> partitionMap;
    try {
      DatabaseDefinitionStore databaseDefStore = new DatabaseDefinitionStore(databaseDefFile);
      if (!databaseDefFile.exists()) {
        createDefaultDatabaseDefinition(databaseDefStore);
      }
      partitionMap = databaseDefStore.read().getPartitions();
    } catch (IOException e) {
      throw new IllegalStateException("Failed to load database config", e);
    }

    String[] activeNodeUris =
        partitionMap
            .values()
            .stream()
            .reduce((s1, s2) -> Sets.union(s1, s2))
            .get()
            .stream()
            .map(this::nodeToUri)
            .toArray(String[]::new);

    String localNodeUri = nodeToUri(NodeInfo.of(clusterService.getLocalNode()));
    Protocol protocol = new CopycatCommunicationProtocol(clusterService, clusterCommunicator);

    ClusterConfig clusterConfig =
        new ClusterConfig()
            .withProtocol(protocol)
            .withElectionTimeout(electionTimeoutMillis(activeNodeUris))
            .withHeartbeatInterval(heartbeatTimeoutMillis(activeNodeUris))
            .withMembers(activeNodeUris)
            .withLocalMember(localNodeUri);

    CopycatConfig copycatConfig =
        new CopycatConfig()
            .withName("onos")
            .withClusterConfig(clusterConfig)
            .withDefaultSerializer(new DatabaseSerializer())
            .withDefaultExecutor(
                Executors.newSingleThreadExecutor(
                    new NamedThreadFactory("copycat-coordinator-%d")));

    coordinator = new DefaultClusterCoordinator(copycatConfig.resolve());

    DatabaseConfig inMemoryDatabaseConfig =
        newDatabaseConfig(BASE_PARTITION_NAME, newInMemoryLog(), activeNodeUris);
    inMemoryDatabase =
        coordinator.getResource(
            inMemoryDatabaseConfig.getName(),
            inMemoryDatabaseConfig
                .resolve(clusterConfig)
                .withSerializer(copycatConfig.getDefaultSerializer())
                .withDefaultExecutor(copycatConfig.getDefaultExecutor()));

    List<Database> partitions =
        partitionMap
            .entrySet()
            .stream()
            .map(
                entry -> {
                  String[] replicas =
                      entry.getValue().stream().map(this::nodeToUri).toArray(String[]::new);
                  return newDatabaseConfig(entry.getKey(), newPersistentLog(), replicas);
                })
            .map(
                config -> {
                  Database db =
                      coordinator.getResource(
                          config.getName(),
                          config
                              .resolve(clusterConfig)
                              .withSerializer(copycatConfig.getDefaultSerializer())
                              .withDefaultExecutor(copycatConfig.getDefaultExecutor()));
                  return db;
                })
            .collect(Collectors.toList());

    partitionedDatabase = new PartitionedDatabase("onos-store", partitions);

    CompletableFuture<Void> status =
        coordinator
            .open()
            .thenCompose(
                v ->
                    CompletableFuture.allOf(inMemoryDatabase.open(), partitionedDatabase.open())
                        .whenComplete(
                            (db, error) -> {
                              if (error != null) {
                                log.error("Failed to initialize database.", error);
                              } else {
                                log.info("Successfully initialized database.");
                              }
                            }));

    Futures.getUnchecked(status);

    transactionManager = new TransactionManager(partitionedDatabase, consistentMapBuilder());
    partitionedDatabase.setTransactionManager(transactionManager);

    eventDispatcher =
        Executors.newSingleThreadExecutor(
            groupedThreads("onos/store/manager", "map-event-dispatcher"));

    queuePollExecutor =
        Executors.newFixedThreadPool(4, groupedThreads("onos/store/manager", "queue-poll-handler"));

    clusterCommunicator.<String>addSubscriber(
        QUEUE_UPDATED_TOPIC,
        data -> new String(data, Charsets.UTF_8),
        name -> {
          DefaultDistributedQueue q = queues.get(name);
          if (q != null) {
            q.tryPoll();
          }
        },
        queuePollExecutor);
    log.info("Started");
  }
 /**
  * Opens ActiveRecord object and associated underlying database
  *
  * @throws ActiveRecordException
  */
 public void open() throws ActiveRecordException {
   m_Database.open();
 }
 /**
  * Creates and opens new ActiveRecord object instance and underlying database. Returned
  * ActiveRecord object is fully ready for use.
  *
  * @param ctx
  * @param dbName
  * @return
  * @throws ActiveRecordException
  */
 public static ActiveRecordBase open(Context ctx, String dbName, int dbVersion)
     throws ActiveRecordException {
   Database db = Database.createInstance(ctx, dbName, dbVersion);
   db.open();
   return ActiveRecordBase.createInstance(db);
 }
예제 #6
0
 /**
  * @throws IOException
  * @throws DataPerfectLibException
  */
 @Before
 public void setUp() throws IOException, DataPerfectLibException {
   database = new Database(new File("src/test/resources/DP26G/TUTORIAL_DATABASES/UD/ud.str"));
   database.open();
 }
  @Override
  public void run() {
    Log.v(Program.LOG, "DatabaseSearcher.run()");

    double radius =
        PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(context.getResources().getString(R.string.radius), 20);

    Location l = StoreFinderApplication.getLastKnownLocation();

    double lat = l.getLatitude();
    double lon = l.getLongitude();

    database = database.open();
    db = database.getDatabase();

    Cursor c =
        db.query(
            "store",
            new String[] {
              "_id", "name", "address", "city", "state", "zip", "phone", "latitude", "longitude"
            },
            "latitude > "
                + (lat - radius / MILES_PER_LATLONG)
                + " AND latitude < "
                + (lat + radius / MILES_PER_LATLONG)
                + " AND longitude > "
                + (lon - radius / MILES_PER_LATLONG)
                + " AND longitude < "
                + (lon + radius / MILES_PER_LATLONG),
            null,
            null,
            null,
            null);

    double latitude, longitude;

    c.moveToFirst();
    if (c.getCount() > 0) {
      do {
        latitude = c.getDouble(7);
        longitude = c.getDouble(8);
        float[] results = new float[3];
        Location.distanceBetween(lat, lon, latitude, longitude, results);
        double distance = results[0] * Program.MILES_PER_METER;

        if (distance > radius) // Make user customizable search distance
        continue;

        Store store = new Store();
        store.setId(c.getInt(0));
        store.setName(c.getString(1));
        store.setAddress(c.getString(2));
        store.setCitystate(c.getString(3) + ", " + c.getString(4) + " " + c.getString(5));
        store.setPhone(c.getString(6));
        store.setDistance(distance);

        Location loc = new Location("");
        loc.setLatitude(latitude);
        loc.setLongitude(longitude);
        store.setLocation(loc);

        Message msg = new Message();
        Bundle b = new Bundle();
        b.putSerializable("store", store);
        msg.setData(b);
        msg.what = WHAT_SEARCHDB;
        handler.sendMessage(msg);
      } while (c.moveToNext());
    }

    c.close();
    database.close();

    Message finish = new Message();
    finish.what = WHAT_FINISHEDSEARCH;
    handler.sendMessage(finish);
  }