コード例 #1
0
ファイル: Interface.java プロジェクト: ssidhanta/Consistify
 // private ArrayList<RegistryEntry> readFromRegister(String key, Session session) {
 private String readFromRegister(String key, Session session) {
   // TODO Auto-generated method stub
   // Map<String, String> resultMap = new HashMap<String, String>();
   String CLID = null, STATUS = null;
   String cqlStr = "SELECT * from consistify.registry WHERE key='" + key + "'";
   Statement statement = new SimpleStatement(cqlStr);
   ResultSet results = session.execute(statement);
   CopyOnWriteArrayList<RegistryEntry> rList = new CopyOnWriteArrayList<RegistryEntry>();
   RegistryEntry r = null;
   Scheduler scheduler = new Scheduler();
   for (Row aRow : results) {
     // if (!resultMap.containsKey(aRow.getKey())) {
     if (aRow.getString("CREATETIME") != null && aRow.getString("key").equalsIgnoreCase(key)) {
       r = new RegistryEntry();
       r.setKey(aRow.getString("key"));
       // System.out.println("**222*CLID:=="+aRow.getString("CLID"));
       r.setCLID(aRow.getString("CLID"));
       r.setDEADLINE(aRow.getString("DEADLINE"));
       r.setINDEX(aRow.getString("INDIC"));
       r.setLATENCYDEP(aRow.getString("LATENCYDEP"));
       r.setWAITINGTIME(aRow.getString("WAITINGTIME"));
       r.setSTATUS(aRow.getString("STATUS"));
       r.setCREATETIME(aRow.getString("CREATETIME"));
       rList.add(r);
     }
     // resultMap.put(aRow.getKey(), ++rowCnt);
     // System.out.println(aRow.getKey() + ":" + rowCnt);
     // }
   }
   // CLID = scheduler.schedule(rList).split(":")[0];
   CLID = scheduler.schedule(rList);
   // System.out.println("****CLID:="+CLID);
   return CLID;
 }
コード例 #2
0
  /**
   * Test of schedule method, immediate execution, blocking in the scheduled task, of class
   * Scheduler.
   */
  @Test
  public void scheduleImmediateBlocking() {
    System.out.println("schedule, immediate, blocking");
    final CountDownLatch barrier = new CountDownLatch(1);
    SchedulerTask task =
        new SchedulerTask() {

          public void onSchedule(long timeStamp) {
            try {
              barrier.countDown();
              Thread.sleep(10000000);
            } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
            }
          }
        };
    Quantum interval = Quantum.seconds(2000);
    Scheduler instance = Scheduler.sharedInstance();
    ScheduledTask scheduled = instance.schedule(task, interval, true);
    stasks.add(scheduled);
    try {
      boolean executed = barrier.await(1000, TimeUnit.SECONDS);
      assertTrue(executed);
    } catch (InterruptedException e) {
      fail(e.getMessage());
    }
  }
コード例 #3
0
  /**
   * Here in this method we schedule a flush when the underlying writer is write ready. This allows
   * the writer thread to return without having to fully flush the content to the underlying
   * transport. If there are references queued this will block.
   */
  public synchronized void flush() throws IOException {
    if (closed) {
      throw new TransportException("Flusher is closed");
    }
    boolean block = writer.isBlocking();

    if (!closed) {
      scheduler.schedule(block);
    }
  }
コード例 #4
0
  /**
   * This is used to close the flusher ensuring that all of the data within the writer will be
   * flushed regardless of the amount of data within the writer that needs to be written. If the
   * writer does not block then this waits to be finished.
   */
  public synchronized void close() throws IOException {
    boolean ready = writer.flush();

    if (!closed) {
      closed = true;
    }
    if (!ready) {
      scheduler.schedule(true);
    }
  }
コード例 #5
0
  public void start() {
    scheduler.schedule(
        new SchedulerTask() {
          public void run() {
            cleanOldSchedules();
          }

          private void cleanOldSchedules() {
            Common.d("cleaning old schedules at time: " + dateFormat.format(new Date()));
            Clean clean = new Clean();
            clean.cleanSchedules();
          }
        },
        new DailyIterator(hourOfDay, minute, second));
    Common.d("ScheduledClean:: clean scheduled at " + hourOfDay + ":" + minute + ":" + second);
  }
コード例 #6
0
  /** Test of unschedule method, of class Scheduler. */
  @Test
  public void unschedule() {
    System.out.println("unschedule");
    final AtomicBoolean executed = new AtomicBoolean(false);
    SchedulerTask task =
        new SchedulerTask() {

          public void onSchedule(long timeStamp) {
            executed.set(true);
          }
        };
    Scheduler instance = Scheduler.sharedInstance();
    ScheduledTask scheduled = instance.schedule(task, Quantum.seconds(3), false);
    instance.unschedule(scheduled);

    try {
      Thread.sleep(5000);
    } catch (InterruptedException e) {
      fail(e.getMessage());
    }
    assertFalse(executed.get());
  }
コード例 #7
0
  /** Test of schedule method of class Scheduler. */
  @Test
  public void schedule() {
    System.out.println("schedule");
    final CountDownLatch barrier = new CountDownLatch(1);
    SchedulerTask task =
        new SchedulerTask() {

          public void onSchedule(long timeStamp) {
            barrier.countDown();
          }
        };
    Quantum interval = Quantum.seconds(5);
    Scheduler instance = Scheduler.sharedInstance();
    ScheduledTask scheduled = instance.schedule(task, interval, false);
    stasks.add(scheduled);
    try {
      boolean executed = barrier.await(8, TimeUnit.SECONDS);
      assertTrue(executed);
    } catch (InterruptedException e) {
      fail(e.getMessage());
    }
  }