本文整理汇总了Java中rice.p2p.commonapi.Application类的典型用法代码示例。如果您正苦于以下问题:Java Application类的具体用法?Java Application怎么用?Java Application使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Application类属于rice.p2p.commonapi包,在下文中一共展示了Application类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupPastryNode
import rice.p2p.commonapi.Application; //导入依赖的package包/类
private PastryNode setupPastryNode() throws Exception {
Environment environment = new Environment();
NetworkSimulator<DirectNodeHandle, RawMessage> simulator = new EuclideanNetwork<DirectNodeHandle, RawMessage>(environment);
PastryNodeFactory factory = new DirectPastryNodeFactory(new RandomNodeIdFactory(environment), simulator, environment);
PastryNode pastryNode = spy(factory.newNode());
if (testName.getMethodName().equals("testSendScribeMessageFromRandomOrigin"))
doReturn(endpoint).when(pastryNode).buildEndpoint(isA(Application.class), isA(String.class));
return pastryNode;
}
示例2: before
import rice.p2p.commonapi.Application; //导入依赖的package包/类
@Before
public void before() {
applicationActivatedLatch = new CountDownLatch(1);
interApplicationDependenciesStore = mock(InterApplicationDependenciesStore.class);
messageContext = mock(ReceivedMessageContext.class);
when(messageContext.getReceivedEntity()).thenReturn(new EchoPayload());
Environment env = new Environment();
Id foriegnId = rice.pastry.Id.build("foriegnNodeHandle");
PId pid = mock(PId.class);
when(pid.getIdAsHex()).thenReturn(foriegnId.toStringFull());
idFactory = mock(KoalaIdFactory.class);
when(idFactory.convertToPId((Id) anyObject())).thenReturn(pid);
when(idFactory.buildId(pid)).thenReturn(foriegnId);
foriegnNodeHandle = mock(NodeHandle.class);
when(foriegnNodeHandle.getId()).thenReturn(foriegnId);
rice.pastry.NodeHandle localNodeHandle = mock(rice.pastry.NodeHandle.class);
when(localNodeHandle.getId()).thenReturn(localNodeId);
deadNodeHandle = mock(rice.pastry.NodeHandle.class);
when(deadNodeHandle.getId()).thenReturn(rice.pastry.Id.build("deadAsADoorNail"));
when(deadNodeHandle.checkLiveness()).thenReturn(false);
router = mock(Router.class);
past = mock(KoalaDHTStorage.class);
when(past.getEnvironment()).thenReturn(env);
pn = mock(PastryNode.class);
when(pn.getEnvironment()).thenReturn(env).thenReturn(env).thenReturn(env).thenReturn(env).thenReturn(env);
when(pn.getRouter()).thenReturn(router);
when(pn.getId()).thenReturn(localNodeId);
when(pn.getNodeId()).thenReturn(localNodeId);
when(pn.getLocalNodeHandle()).thenReturn(localNodeHandle);
when(pn.buildEndpoint(isA(Application.class), isA(String.class))).thenAnswer(new Answer<PastryEndpoint>() {
@Override
public PastryEndpoint answer(InvocationOnMock invocation) throws Throwable {
return new PastryEndpoint(pn, (Application) invocation.getArguments()[0], (String) invocation.getArguments()[1], true);
}
});
KoalaPiEntityFactory koalaPiEntityFactory = new KoalaPiEntityFactory();
koalaPiEntityFactory.setKoalaJsonParser(new KoalaJsonParser());
ArrayList<PiEntity> applicationPayloads = new ArrayList<PiEntity>();
applicationPayloads.add(new EchoPayload());
koalaPiEntityFactory.setPiEntityTypes(applicationPayloads);
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.initialize();
AlwaysOnApplicationActivator aa = new AlwaysOnApplicationActivator();
aa.setScheduledExecutorService(Executors.newScheduledThreadPool(4));
aa.setApplicationRegistry(new ApplicationRegistry());
aa.setExecutor(executor);
echoApplication = new EchoApplication() {
@Override
public boolean becomeActive() {
boolean res = super.becomeActive();
applicationActivatedLatch.countDown();
return res;
}
};
echoApplication.setApplicationActivator(aa);
echoApplication.setKoalaPiEntityFactory(koalaPiEntityFactory);
echoApplication.setKoalaJsonParser(new KoalaJsonParser());
echoApplication.setKoalaIdFactory(idFactory);
ReflectionTestUtils.setField(aa, "interApplicationDependenciesStore", interApplicationDependenciesStore);
LogHelper.initLogging();
}