Package org.apache.hadoop.hdfs.notifier

Examples of org.apache.hadoop.hdfs.notifier.NamespaceNotification


    long txCount = 1001;
   
    new Thread(history).start();
   
    for (long txId = 0; txId < txCount; txId ++) {
      history.storeNotification(new NamespaceNotification("/a/" + txId,
          EventType.FILE_ADDED.getByteValue(), txId));
    }

    // Part 1 - Get all notifications
    historyNotifications = new LinkedList<NamespaceNotification>();
    history.addNotificationsToQueue(new NamespaceEvent("/a",
        EventType.FILE_ADDED.getByteValue()), 0, historyNotifications);
    Assert.assertEquals(1000, historyNotifications.size());
    for (long txId = 1; txId < txCount; txId ++) {
      NamespaceNotification n = historyNotifications.poll();
      Assert.assertEquals(txId, n.txId);
      Assert.assertEquals("/a/" + txId, n.path);
      Assert.assertEquals(EventType.FILE_ADDED.getByteValue(), n.type);
    }
   
    // Part 2 - Get half of the notifications
    historyNotifications = new LinkedList<NamespaceNotification>();
    history.addNotificationsToQueue(new NamespaceEvent("/a",
        EventType.FILE_ADDED.getByteValue()), 500, historyNotifications);
    Assert.assertEquals(500, historyNotifications.size());
    for (long txId = 501; txId < txCount; txId ++) {
      NamespaceNotification n = historyNotifications.poll();
      Assert.assertEquals(txId, n.txId);
      Assert.assertEquals("/a/" + txId, n.path);
      Assert.assertEquals(EventType.FILE_ADDED.getByteValue(), n.type);
    }
   
View Full Code Here


   
    @Override
    public void run() {
      try {
        while (!shutdownPending()) {
          NamespaceNotification n = logReader.getNamespaceNotification();
          if (n != null)
            handleNotification(n);
        }
      } catch (IOException e) {
        LOG.error("DummyServerCore failed reading notifications", e);
View Full Code Here

    core.addClient(new ClientData(id2, handler2, "host", 3001));
   
    Set<Long> clientsForNotification;
    core.subscribeClient(id1, event, -1);
    clientsForNotification = core.getClientsForNotification(
        new NamespaceNotification("/a/b", event.type, 10));
    Assert.assertEquals(1, clientsForNotification.size());
    Assert.assertTrue(clientsForNotification.contains(id1));
   
    core.subscribeClient(id2, event, -1);
    clientsForNotification = core.getClientsForNotification(
        new NamespaceNotification("/a/b", event.type, 10));
    Assert.assertEquals(2, clientsForNotification.size());
    Assert.assertTrue(clientsForNotification.contains(id1));
    Assert.assertTrue(clientsForNotification.contains(id2));
   
    core.unsubscribeClient(id1, event);
    clientsForNotification = core.getClientsForNotification(
        new NamespaceNotification("/a/b", event.type, 10));
    Assert.assertEquals(1, clientsForNotification.size());
    Assert.assertTrue(clientsForNotification.contains(id2));
   
    core.unsubscribeClient(id2, event);
    clientsForNotification = core.getClientsForNotification(
        new NamespaceNotification("/a/b", event.type, 10));
    if (clientsForNotification != null)
      Assert.assertEquals(0, clientsForNotification.size());
   
    // Test that TransactionIdTooOldException is thrown
    try {
View Full Code Here

        new LinkedList<NamespaceNotification>();
    Queue<NamespaceNotification> historyExpectedQueue =
        new LinkedList<NamespaceNotification>();
    for (long txId = 0; txId < txIdCount; txId ++) {
      String basePath = possiblePaths[generator.nextInt(3)];
      NamespaceNotification n = new NamespaceNotification(basePath + txId,
          EventType.FILE_ADDED.getByteValue(), txId);
     
      historyExpectedQueue.add(n);
      if (basePath.equals("/a/") || basePath.equals("/c/"))
        client1ExpectedQueue.add(n);
View Full Code Here

      if (txId == -2)
        throw new TransactionIdTooOldException();
     
      // Using -3 to mark we should add these 2 notifications
      if (txId == -3) {
        notifications.add(new NamespaceNotification("/a/b",
            EventType.FILE_ADDED.getByteValue(), 20));
        notifications.add(new NamespaceNotification("/a/c",
            EventType.FILE_ADDED.getByteValue(), 30));
      }
    }
View Full Code Here

    started = true;
    try {
      while (!shutdownPending()) {
        // Read a notification
        NamespaceNotification notification =
            logReader.getNamespaceNotification();
        if (notification != null) {
          handleNotification(notification);
          continue;
        }
View Full Code Here

          continue;
        }
       
        String entryPath = entry.getFullPath();
        if (entryPath.startsWith(dirFormatPath)) {
          notifications.add(new NamespaceNotification(entryPath, entry.type, entry.txnId));
        }
      }
    } finally {
      historyLock.readLock().unlock();
    }
View Full Code Here

   * @throws IOException raised when a fatal error occurred.
   */
  public NamespaceNotification getNamespaceNotification()
      throws IOException {
    FSEditLogOp op = null;
    NamespaceNotification notification = null;
   
    // Keep looping until we reach an operation that can be
    // considered a notification.
    while (true) {
      if (LOG.isDebugEnabled()) {
View Full Code Here

   *           raised when a fatal error occurred.
   */
  @Override
  public NamespaceNotification getNamespaceNotification() throws IOException {
    FSEditLogOp op = null;
    NamespaceNotification notification = null;

    // Keep looping until we reach an operation that can be
    // considered a notification.
    while (true) {
     
View Full Code Here

   *         NamespaceNotification.
   */
  static NamespaceNotification createNotification(FSEditLogOp op) {
    switch (op.opCode) {
      case OP_ADD:
        return new NamespaceNotification(((AddOp)op).path,
            EventType.FILE_ADDED.getByteValue(), op.getTransactionId());

      case OP_CLOSE:
        return new NamespaceNotification(((CloseOp)op).path,
            EventType.FILE_CLOSED.getByteValue(), op.getTransactionId());
       
      case OP_DELETE:
        return new NamespaceNotification(((DeleteOp)op).path,
            EventType.NODE_DELETED.getByteValue(), op.getTransactionId());
       
      case OP_MKDIR:
        return new NamespaceNotification(((MkdirOp)op).path,
            EventType.DIR_ADDED.getByteValue(), op.getTransactionId());
      default:
        return null;
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hdfs.notifier.NamespaceNotification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.