当前位置: 首页>>代码示例>>Java>>正文


Java NodeHandle类代码示例

本文整理汇总了Java中rice.pastry.NodeHandle的典型用法代码示例。如果您正苦于以下问题:Java NodeHandle类的具体用法?Java NodeHandle怎么用?Java NodeHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NodeHandle类属于rice.pastry包,在下文中一共展示了NodeHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newNode

import rice.pastry.NodeHandle; //导入依赖的package包/类
/**
   * Method which creates a Pastry node from the next port with the specified nodeId 
   * (or one generated from the NodeIdFactory if not specified)
   * 
   * @param pilot Node handle to bootstrap from.
   * @param nodeId if non-null, will use this nodeId for the node, rather than using the NodeIdFactory
   * @return A node with a random ID and next port number.
   */
  public PastryNode newNode(NodeHandle nodeHandle, Id id, InetSocketAddress proxyAddress) {
    PastryNode n = newNode(id, proxyAddress);
    if (nodeHandle == null) {
      n.getBootstrapper().boot(null); 
    } else {
      BogusNodeHandle bnh = (BogusNodeHandle)nodeHandle;
      n.getBootstrapper().boot(bnh.addresses);
      
      // delme
//      InetSocketAddressLookup inetLookupService = (InetSocketAddressLookup)((PastryNode)n).getVars().get(SocketPastryNodeFactory.IP_ADDR_SERVICE);
//      inetLookupService.getMyInetAddress(bnh.addresses.iterator().next(), new Continuation<InetSocketAddress, Exception>() {
//      
//        public void receiveResult(InetSocketAddress result) {
//          System.out.println("My ("+n+") Address is "+result);
//        }
//      
//        public void receiveException(Exception exception) {
//          // TODO Auto-generated method stub
//      
//        }      
//      }, null);
      // emled
    }
    return n;
  }
 
开发者ID:barnyard,项目名称:pi,代码行数:34,代码来源:SocketPastryNodeFactory.java

示例2: getRendezvousPoint

import rice.pastry.NodeHandle; //导入依赖的package包/类
public RendezvousSocketNodeHandle getRendezvousPoint(RendezvousSocketNodeHandle dest, Map<String, Object> options) {
  ArrayList<RendezvousSocketNodeHandle> choiceSet = new ArrayList<RendezvousSocketNodeHandle>();
  for (NodeHandle nh : pn.getLeafSet()) {
    RendezvousSocketNodeHandle rnh = (RendezvousSocketNodeHandle)nh;
    if (rnh.canContactDirect()) {
      choiceSet.add(rnh);
    }
  }
  if (choiceSet.size() == 0) {
    // We can't find a rendezvous point!!!
    // should probably log this
    return null;
  }
  
  return choiceSet.get(random.nextInt(choiceSet.size()));
}
 
开发者ID:barnyard,项目名称:pi,代码行数:17,代码来源:LeafSetRendezvousStrategy.java

示例3: getNearHandlesHelper

import rice.pastry.NodeHandle; //导入依赖的package包/类
/**
 * Don't return any non-contactDirect handles unless all of them are.
 */
@Override
protected List<NodeHandle> getNearHandlesHelper(List<NodeHandle> handles) {
  ArrayList<NodeHandle> contactDirect = new ArrayList<NodeHandle>();
  ArrayList<NodeHandle> notContactDirect = new ArrayList<NodeHandle>();
  
  for (NodeHandle foo : handles) {
    RendezvousSocketNodeHandle rsnh = (RendezvousSocketNodeHandle)foo;
    if (rsnh.canContactDirect()) {
      contactDirect.add(foo);
    } else {
      notContactDirect.add(foo);        
    }
  }
  if (contactDirect.isEmpty()) return notContactDirect;
  return contactDirect;
}
 
开发者ID:barnyard,项目名称:pi,代码行数:20,代码来源:RendezvousPNSApplication.java

示例4: getNearHandles

import rice.pastry.NodeHandle; //导入依赖的package包/类
/**
 * This is the first step, cull out the bootHandles that we can't use good.
 */
@Override
public Cancellable getNearHandles(Collection<NodeHandle> bootHandles,
    Continuation<Collection<NodeHandle>, Exception> deliverResultToMe) {
  ArrayList<NodeHandle> newBootHandles = new ArrayList<NodeHandle>();
  if (logger.level <= Logger.INFO) logger.log("Booting off of "+bootHandles.size()+" nodes. "+bootHandles);
  for (NodeHandle handle : bootHandles) {
    if (useHandle(handle)) {
      newBootHandles.add(handle);
    } else {
      if (logger.level <= Logger.WARNING) logger.log("Can't use "+handle+" it is firewalled.");
    }
  }
  
  return super.getNearHandles(newBootHandles, deliverResultToMe);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:19,代码来源:RendezvousPNSApplication.java

示例5: getLeafSet

import rice.pastry.NodeHandle; //导入依赖的package包/类
@Override
  public Cancellable getLeafSet(final NodeHandle input,
      final Continuation<LeafSet, Exception> c) {
//    logger.log(this+".getLeafSet("+input+")");
    if (ignore(input, c)) return null;
    return super.getLeafSet(input, new Continuation<LeafSet, Exception>() {
    
      public void receiveResult(LeafSet result) {
        for (NodeHandle handle : result) {
          if (!useHandle(handle)) {
            if (logger.level <= Logger.FINE) logger.log("getLeafSet("+input+") Dropping "+handle);
            result.remove(handle);
          }
        }
        c.receiveResult(result);
      }
    
      public void receiveException(Exception exception) {
        c.receiveException(exception);
      }    
    });
  }
 
开发者ID:barnyard,项目名称:pi,代码行数:23,代码来源:RendezvousPNSApplication.java

示例6: sendTheMessage

import rice.pastry.NodeHandle; //导入依赖的package包/类
@Override
  protected void sendTheMessage(RouteMessage rm, NodeHandle handle) {
//    logger.log("sendTheMessage("+rm+","+handle+") reroute:"+rm.getOptions().rerouteIfSuspected());
    if (rm.getOptions().multipleHopsAllowed() && rm.getOptions().rerouteIfSuspected()) {
      // can be rapidly rerouted
      if (handle.getLiveness() >= LIVENESS_SUSPECTED) {
//        if (logger.level <= Logger.WARNING) logger.log("Reroutable message "+rm+" sending to non-alive node:"+handle+" liveness:"+handle.getLiveness());
        super.sendTheMessage(rm, handle);
        return;
      }
      
      RouterNotification notifyMe = new RouterNotification(rm, handle);
      addToPending(notifyMe, handle);
      rm.setTLCancellable(notifyMe);
      notifyMe.setCancellable(thePastryNode.send(handle, rm, notifyMe, rm.getTLOptions()));
    } else {
      super.sendTheMessage(rm, handle);
    }
  }
 
开发者ID:barnyard,项目名称:pi,代码行数:20,代码来源:RapidRerouter.java

示例7: isClosestNodeToSuperNodeCheckPoint

import rice.pastry.NodeHandle; //导入依赖的package包/类
private boolean isClosestNodeToSuperNodeCheckPoint(ActivationAwareApplication application, String superNodeCheckPoint) {
    Id localNodeId = koalaIdFactory.generateNodeId();

    SortedSet<String> nodeIds = new TreeSet<String>();
    nodeIds.add(localNodeId.toStringFull());
    Collection<NodeHandle> leafNodeHandles = application.getLeafNodeHandles();
    for (NodeHandle nodeHandle : leafNodeHandles) {
        String remoteNodeId = nodeHandle.getNodeId().toStringFull();
        if (PId.getRegionFromId(remoteNodeId) == koalaIdFactory.getRegion() && PId.getAvailabilityZoneFromId(remoteNodeId) == koalaIdFactory.getAvailabilityZoneWithinRegion())
            nodeIds.add(remoteNodeId);
    }

    Id nodeIdClosestToId = koalaIdUtils.getNodeIdClosestToId(nodeIds, koalaIdFactory.buildId(superNodeCheckPoint), NodeScope.AVAILABILITY_ZONE);
    LOG.debug(String.format("%s is closest to %s (local id is %s)", superNodeCheckPoint, nodeIdClosestToId.toStringFull(), localNodeId.toStringFull()));
    return localNodeId.equals(nodeIdClosestToId);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:17,代码来源:SuperNodeApplicationActivator.java

示例8: removeFromPending

import rice.pastry.NodeHandle; //导入依赖的package包/类
/**
 * Return true if it was still pending.
 * 
 * @param notifyMe
 * @param handle
 * @return true if still pending
 */
private boolean removeFromPending(RouterNotification notifyMe, NodeHandle handle) {
  synchronized(pending) {
    Collection<RouterNotification> c = pending.get(handle);
    if (c == null) {
      if (logger.level <= Logger.FINE) logger.log("removeFromPending("+notifyMe+","+handle+") had no pending messages for handle.");
      return false;
    }
    boolean ret = c.remove(notifyMe);
    if (c.isEmpty()) {
      pending.remove(handle);
    }
    if (!ret) {
      if (logger.level <= Logger.FINE) logger.log("removeFromPending("+notifyMe+","+handle+") msg was not there."); 
    }
    return ret;
  }    
}
 
开发者ID:barnyard,项目名称:pi,代码行数:25,代码来源:RapidRerouter.java

示例9: loadCheckpoint

import rice.pastry.NodeHandle; //导入依赖的package包/类
/**
 * Load rt/leafset
 */
public boolean loadCheckpoint(InputBuffer buffer) throws IOException {
  Environment environment = ((Verifier<TransportLayerNodeHandle<MultiInetSocketAddress>>)tl).getEnvironment();
  Id nodeId = Id.build(buffer);
  pn = new PastryNode(nodeId, environment);
  NodeHandleFactory nodeHandleFactory = nodeFactory.getNodeHandleFactory(pn);
  NodeHandle handle = nodeHandleFactory.readNodeHandle(buffer);
  // put this in the localHandleTable, where it will be read/removed in the hacked PastryNodeFactory
  nodeFactory.localHandleTable.put(pn,handle); 
  nodeFactory.nodeHandleHelper(pn);

  // load rt/leafset, liveness state
  // register witness searching algorithm

  return true;
}
 
开发者ID:barnyard,项目名称:pi,代码行数:19,代码来源:PeerReviewCallbackImpl.java

示例10: before

import rice.pastry.NodeHandle; //导入依赖的package包/类
@Before
public void before() {
	id = Id.build("moo");
	
	nodeHandle = mock(NodeHandle.class);
	
	List<NodeHandle> routingCandidateList = new ArrayList<NodeHandle>();
	routingCandidateList.add(nodeHandle);
	router = mock(Router.class);
	when(router.getBestRoutingCandidates(id)).thenReturn(routingCandidateList.iterator());
	
	logger = mock(Logger.class);
       logManager = mock(LogManager.class);
       when(logManager.getLogger(isA(Class.class), isA(String.class))).thenReturn(logger);

       environment = mock(Environment.class);
       when(environment.getLogManager()).thenReturn(logManager);
	
	pastryNode = mock(PastryNode.class);
       when(pastryNode.getEnvironment()).thenReturn(environment);
       when(pastryNode.getRouter()).thenReturn(router);
       
       routeMessage = mock(RouteMessage.class);
       
	this.routingMessageRedirector = new RoutingMessageRedirector(pastryNode);
}
 
开发者ID:barnyard,项目名称:p2p-core,代码行数:27,代码来源:RoutingMessageRedirectorTest.java

示例11: getWitnesses

import rice.pastry.NodeHandle; //导入依赖的package包/类
public void getWitnesses(
    final Id subject,
    final WitnessListener<TransportLayerNodeHandle<MultiInetSocketAddress>, Id> callback) {
  fetchLeafSetApp.getNeighbors(subject,new Continuation<Collection<NodeHandle>, Exception>() {
  
    public void receiveResult(Collection<NodeHandle> result) {
      ArrayList<TransportLayerNodeHandle<MultiInetSocketAddress>> ret = new ArrayList<TransportLayerNodeHandle<MultiInetSocketAddress>>(result.size());
      for (NodeHandle nh : result) {
        if (!nh.getId().equals(subject)) ret.add((TransportLayerNodeHandle<MultiInetSocketAddress>)nh);
      }
      logger.log("returning witnesses for "+subject+" "+ret);
      callback.notifyWitnessSet(subject, ret);
    }
  
    public void receiveException(Exception exception) {
      throw new RuntimeException(exception);
    }
  
  });
}
 
开发者ID:barnyard,项目名称:pi,代码行数:21,代码来源:PeerReviewCallbackImpl.java

示例12: PastryEndpointMessage

import rice.pastry.NodeHandle; //导入依赖的package包/类
public PastryEndpointMessage(int address, InputBuffer buf, MessageDeserializer md, short type, int priority, NodeHandle sender) throws IOException {
    super(address);

    byte version = 0;//buf.readByte();
    switch(version) {
      case 0:
        setSender(sender);
    //    isRaw = buf.readBoolean();
//        byte priority = buf.readByte();
//        short type = buf.readShort();
        if (type == 0) {
          message = new JavaSerializedMessage(md.deserialize(buf, type, priority, sender));
        } else {
          message = (RawMessage)md.deserialize(buf, type, priority, sender); 
        }
        if (getMessage() == null) throw new IOException("PEM.deserialize() message = null type:"+type+" md:"+md);
//    System.out.println("PEM.deserialize() message:"+message+" type:"+type+" md:"+md);
        break;
      default:
        throw new IOException("Unknown Version: "+version);
    }
    
  }
 
开发者ID:barnyard,项目名称:pi,代码行数:24,代码来源:PastryEndpointMessage.java

示例13: shouldForwardIfDestinationAppSameAsSourceApp

import rice.pastry.NodeHandle; //导入依赖的package包/类
@Test
public void shouldForwardIfDestinationAppSameAsSourceApp() throws Exception {
    ApplicationMessage appMessage = new ApplicationMessage(parser.getJson(testPayload), someId.toStringFull(), EntityMethod.CREATE, null, koalaPastryApplication.getApplicationName(), koalaPastryApplication.getApplicationName());

    rice.pastry.NodeHandle someOtherNodeHandle = mock(rice.pastry.NodeHandle.class);
    when(someOtherNodeHandle.getNodeId()).thenReturn(rice.pastry.Id.build("unknown"));

    rice.pastry.routing.RouteMessage routeMessage = mock(rice.pastry.routing.RouteMessage.class);
    when(routeMessage.getMessage(isA(MessageDeserializer.class))).thenReturn(appMessage);
    when(routeMessage.getNextHop()).thenReturn(someOtherNodeHandle);

    // act
    boolean res = koalaPastryApplication.forward(routeMessage);

    // assert
    assertNotNull(payloadToForward);
    assertFalse(isForThisNode);
    assertFalse(res);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:20,代码来源:KoalaPastryApplicationBaseTest.java

示例14: shouldRoutePayloadInTransaction

import rice.pastry.NodeHandle; //导入依赖的package包/类
@Test
public void shouldRoutePayloadInTransaction() {
    // setup
    messageContext = new MessageContext(handlingApp, TRANSACTION_UID);

    // act
    messageContext.routePiMessageToApplication(someId, EntityMethod.GET, piEntity, "some-other-app");

    // verify
    verify(endpoint).route(eq(koalaIdFactory.buildId(someId)), argThat(new ArgumentMatcher<ApplicationMessage>() {
        public boolean matches(Object argument) {
            ApplicationMessage arg = (ApplicationMessage) argument;
            assertEquals(TRANSACTION_UID, arg.getTransactionUID());
            return true;
        }
    }), (NodeHandle) eq(null));
}
 
开发者ID:barnyard,项目名称:p2p-core,代码行数:18,代码来源:MessageContextTest.java

示例15: closestToMe

import rice.pastry.NodeHandle; //导入依赖的package包/类
/**
 * This method returns the closest node to the current node out of
 * the union of the provided handle and the node handles in the
 * leafset
 *
 * @param handle The handle to include
 * @param leafSet The leafset to include
 * @return The closest node out of handle union leafset
 */
private Cancellable closestToMe(NodeHandle handle, LeafSet leafSet, Continuation<NodeHandle, Exception> c)  {
  if (leafSet == null) {
    c.receiveResult(handle);
    return null;
  }
  HashSet<NodeHandle> handles = new HashSet<NodeHandle>();

  for (int i = 1; i <= leafSet.cwSize() ; i++)
    handles.add(leafSet.get(i));

  for (int i = -leafSet.ccwSize(); i < 0; i++)
    handles.add(leafSet.get(i));

  return closestToMe(handle, handles, c);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:25,代码来源:PNSApplication.java


注:本文中的rice.pastry.NodeHandle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。