本文整理汇总了Java中rice.pastry.PastryNodeFactory类的典型用法代码示例。如果您正苦于以下问题:Java PastryNodeFactory类的具体用法?Java PastryNodeFactory怎么用?Java PastryNodeFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PastryNodeFactory类属于rice.pastry包,在下文中一共展示了PastryNodeFactory类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exampleA
import rice.pastry.PastryNodeFactory; //导入依赖的package包/类
public static PastryNodeFactory exampleA(int bindport, Environment env,
NodeIdFactory nidFactory, final int amt, final int time) throws IOException {
// anonymously extend SPNF
PastryNodeFactory factory = new SocketPastryNodeFactory(nidFactory, bindport, env) {
/**
* Override getWireTransportLayer to return the BandwidthLimitingTL wrapping
* the default wire implementation.
*/
@Override
protected TransportLayer<InetSocketAddress, ByteBuffer> getWireTransportLayer(
InetSocketAddress innermostAddress, PastryNode pn) throws IOException {
// get the default layer
TransportLayer<InetSocketAddress, ByteBuffer> wtl =
super.getWireTransportLayer(innermostAddress, pn);
// wrap it with our layer
return new BandwidthLimitingTransportLayer<InetSocketAddress>(
wtl, amt, time, pn.getEnvironment());
}
};
return factory;
}
示例2: exampleB
import rice.pastry.PastryNodeFactory; //导入依赖的package包/类
public static PastryNodeFactory exampleB(int bindport, Environment env,
NodeIdFactory nidFactory, final int amt, final int time) throws IOException {
PastryNodeFactory factory = new SocketPastryNodeFactory(nidFactory, bindport, env) {
@Override
protected TransLivenessProximity<MultiInetSocketAddress, ByteBuffer> getSourceRouteManagerLayer(
TransportLayer<SourceRoute<MultiInetSocketAddress>, ByteBuffer> ltl,
LivenessProvider<SourceRoute<MultiInetSocketAddress>> livenessProvider,
Pinger<SourceRoute<MultiInetSocketAddress>> pinger,
PastryNode pn,
MultiInetSocketAddress proxyAddress,
MultiAddressSourceRouteFactory esrFactory) throws IOException {
// get the default layer
final TransLivenessProximity<MultiInetSocketAddress, ByteBuffer> srm =
super.getSourceRouteManagerLayer(
ltl, livenessProvider, pinger, pn, proxyAddress, esrFactory);
// wrap the default layer with our layer
final BandwidthLimitingTransportLayer<MultiInetSocketAddress> bll =
new BandwidthLimitingTransportLayer<MultiInetSocketAddress>(
srm.getTransportLayer(), amt, time, pn.getEnvironment());
return new TransLivenessProximity<MultiInetSocketAddress, ByteBuffer>(){
public TransportLayer<MultiInetSocketAddress, ByteBuffer> getTransportLayer() {
return bll;
}
public LivenessProvider<MultiInetSocketAddress> getLivenessProvider() {
return srm.getLivenessProvider();
}
public ProximityProvider<MultiInetSocketAddress> getProximityProvider() {
return srm.getProximityProvider();
}
};
}
};
return factory;
}
示例3: setupPastryNode
import rice.pastry.PastryNodeFactory; //导入依赖的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;
}
示例4: DirectTutorial
import rice.pastry.PastryNodeFactory; //导入依赖的package包/类
/**
* This constructor launches numNodes PastryNodes. They will bootstrap
* to an existing ring if one exists at the specified location, otherwise
* it will start a new ring.
*
* @param bindport the local port to bind to
* @param bootaddress the IP:port of the node to boot from
* @param numNodes the number of nodes to create in this JVM
* @param env the environment for these nodes
*/
public DirectTutorial(int numNodes, Environment env) throws Exception {
// Generate the NodeIds Randomly
final NodeIdFactory nidFactory = new RandomNodeIdFactory(env);
// create a new network
NetworkSimulator<DirectNodeHandle,RawMessage> simulator = new EuclideanNetwork<DirectNodeHandle,RawMessage>(env);
// stop the simulator to schedule events
simulator.stop();
// construct the PastryNodeFactory, this is how we use rice.pastry.direct, with a Euclidean Network
PastryNodeFactory factory = new DirectPastryNodeFactory(nidFactory, simulator, env);
scheduleBootTask(numNodes, nidFactory, factory, env);
simulator.start();
}
示例5: scheduleBootTask
import rice.pastry.PastryNodeFactory; //导入依赖的package包/类
public void scheduleBootTask(final int numNodes, final NodeIdFactory nidFactory, final PastryNodeFactory factory, final Environment env) {
env.getSelectorManager().getTimer().schedule(new TimerTask() {
// create the handle to boot off of
NodeHandle bootHandle = null;
// counter to construct nodes/apps
int curNode = 0;
@Override
public void run() {
try {
// create the node (note, this does not boot the node)
final PastryNode node = factory.newNode();
System.out.println("Creating new node "+node+" at "+env.getTimeSource().currentTimeMillis());
// create the application
MyApp app = new MyApp(node);
apps.add(app);
// increment the counter
curNode++;
// store curNode to start the next task
final int myCurNode = curNode;
// track when the node is finished booting
node.addObserver(new Observer() {
public void update(Observable o, Object arg) {
try {
if (arg instanceof Boolean) {
System.out.println("Finished creating new node "+node+" at "+env.getTimeSource().currentTimeMillis());
// see if we're done booting nodes
if (myCurNode == numNodes) {
// start the delivery task
scheduleDeliveryTask(nidFactory, env);
}
} else if (arg instanceof JoinFailedException) {
JoinFailedException jfe = (JoinFailedException)arg;
jfe.printStackTrace();
throw new RuntimeException(jfe); // kill selector
}
} finally {
// stop observing after initial try
o.deleteObserver(this);
}
}
});
// boot the node
node.boot(bootHandle);
// store the bootHandle
bootHandle = node.getLocalHandle();
// stop the task when created numNodes
if (curNode >= numNodes) cancel();
} catch (IOException ioe) {
// kill the selector
throw new RuntimeException(ioe);
}
}
}, 0, 1000);
}
示例6: DistTutorial
import rice.pastry.PastryNodeFactory; //导入依赖的package包/类
/**
* This constructor sets up a PastryNode. It will bootstrap to an
* existing ring if it can find one at the specified location, otherwise
* it will start a new ring.
*
* @param bindport the local port to bind to
* @param bootaddress the IP:port of the node to boot from
* @param env the environment for these nodes
*/
public DistTutorial(int bindport, InetSocketAddress bootaddress, Environment env) throws Exception {
// Generate the NodeIds Randomly
NodeIdFactory nidFactory = new RandomNodeIdFactory(env);
// construct the PastryNodeFactory, this is how we use rice.pastry.socket
PastryNodeFactory factory = new SocketPastryNodeFactory(nidFactory, bindport, env);
// construct a node
PastryNode node = factory.newNode();
// construct a new MyApp
MyApp app = new MyApp(node);
node.boot(bootaddress);
// the node may require sending several messages to fully boot into the ring
synchronized(node) {
while(!node.isReady() && !node.joinFailed()) {
// delay so we don't busy-wait
node.wait(500);
// abort if can't join
if (node.joinFailed()) {
throw new IOException("Could not join the FreePastry ring. Reason:"+node.joinFailedReason());
}
}
}
System.out.println("Finished creating new node "+node);
// wait 10 seconds
env.getTimeSource().sleep(10000);
// route 10 messages
for (int i = 0; i < 10; i++) {
// pick a key at random
Id randId = nidFactory.generateNodeId();
// send to that key
app.routeMyMsg(randId);
// wait a sec
env.getTimeSource().sleep(1000);
}
// wait 10 seconds
env.getTimeSource().sleep(10000);
// send directly to my leafset
LeafSet leafSet = node.getLeafSet();
// this is a typical loop to cover your leafset. Note that if the leafset
// overlaps, then duplicate nodes will be sent to twice
for (int i=-leafSet.ccwSize(); i<=leafSet.cwSize(); i++) {
if (i != 0) { // don't send to self
// select the item
NodeHandle nh = leafSet.get(i);
// send the message directly to the node
app.routeMyMsgDirect(nh);
// wait a sec
env.getTimeSource().sleep(1000);
}
}
}
示例7: DistTutorial
import rice.pastry.PastryNodeFactory; //导入依赖的package包/类
/**
* This constructor sets up a PastryNode. It will bootstrap to an
* existing ring if it can find one at the specified location, otherwise
* it will start a new ring.
*
* @param bindport the local port to bind to
* @param bootaddress the IP:port of the node to boot from
*/
public DistTutorial(int bindport, InetSocketAddress bootaddress, Environment env) throws Exception {
// Generate the NodeIds Randomly
NodeIdFactory nidFactory = new RandomNodeIdFactory(env);
// construct the PastryNodeFactory, this is how we use rice.pastry.socket
PastryNodeFactory factory = new SocketPastryNodeFactory(nidFactory, bindport, env);
// This will return null if we there is no node at that location
NodeHandle bootHandle = ((SocketPastryNodeFactory)factory).getNodeHandle(bootaddress);
// construct a node, passing the null boothandle on the first loop will cause the node to start its own ring
PastryNode node = factory.newNode();
// construct a new MyApp
MyApp app = new MyApp(node);
// boot the node
node.boot(bootaddress);
// the node may require sending several messages to fully boot into the ring
synchronized(node) {
while(!node.isReady() && !node.joinFailed()) {
// delay so we don't busy-wait
node.wait(500);
// abort if can't join
if (node.joinFailed()) {
throw new IOException("Could not join the FreePastry ring. Reason:"+node.joinFailedReason());
}
}
}
System.out.println("Finished creating new node "+node);
// wait 15 seconds
env.getTimeSource().sleep(15000);
// cancel the task
app.cancelTask();
}