示例#1
0
  public static void replayNode(
      final Id id,
      final InetSocketAddress addr,
      InetSocketAddress bootaddress,
      final long startTime,
      final long randSeed)
      throws Exception {
    Environment env = new Environment();
    if (env.getParameters()
        .getBoolean("org.mpisws.p2p.testing.transportlayer.replay.Replayer_printlog"))
      printLog("0x" + id.toStringFull().substring(0, 6), env);

    //  Environment env = Environment.directEnvironment();
    System.out.println(
        id.toStringFull()
            + " "
            + addr.getAddress().getHostAddress()
            + " "
            + addr.getPort()
            + " "
            + bootaddress.getPort()
            + " "
            + startTime
            + " "
            + randSeed);
    env.destroy();
    new Replayer(id, addr, bootaddress, startTime, randSeed);
  }
示例#2
0
  private static void doIinitstuff(String args[], Environment env) {
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-verbosity") && i + 1 < args.length) {
        int num = Integer.parseInt(args[i + 1]);
        env.getParameters().setInt("loglevel", num * 100);
        break;
      }
    }

    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-silent") && i + 1 < args.length) {
        env.getParameters().setInt("loglevel", Logger.SEVERE);
        break;
      }
    }

    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-verbose") && i + 1 < args.length) {
        env.getParameters().setInt("loglevel", Logger.ALL);
        break;
      }
    }

    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-nodes") && i + 1 < args.length) numnodes = Integer.parseInt(args[i + 1]);

      if (args[i].equals("-msgs") && i + 1 < args.length) nummsgs = Integer.parseInt(args[i + 1]);

      if (args[i].equals("-simultaneous_joins")) simultaneous_joins = true;

      if (args[i].equals("-simultaneous_msgs")) simultaneous_msgs = true;

      if (args[i].equals("-help")) {
        System.out.println(
            "Usage: HelloWorld [-msgs m] [-nodes n] [-verbose|-silent|-verbosity v]");
        System.out.println("                  [-simultaneous_joins] [-simultaneous_msgs] [-help]");
        System.out.println(
            "  Default verbosity is 8, -verbose is 1, and -silent is 10 (error msgs only).");
        System.exit(1);
      }
    }
  }
 public void setLoggingParams(Environment env) {
   env.getParameters()
       .setInt("org.mpisws.p2p.testing.transportlayer.peerreview_loglevel", Logger.INFO);
   //    env.getParameters().setInt("org.mpisws.p2p.transport.peerreview.audit_loglevel",
   // Logger.FINEST);
 }
示例#4
0
  public Replayer(
      final Id id,
      final InetSocketAddress addr,
      InetSocketAddress bootaddress,
      final long startTime,
      final long randSeed)
      throws Exception {
    this.bootaddress = bootaddress;
    Environment env = ReplayLayer.generateEnvironment(id.toString(), startTime, randSeed, null);

    final Parameters params = env.getParameters();

    params.setInt(
        "pastry_socket_scm_max_open_sockets",
        params.getInt(
            "org.mpisws.p2p.testing.transportlayer.replay_pastry_socket_scm_max_open_sockets"));

    params.setBoolean("pastry_socket_use_own_random", false);
    //    env.getParameters().setInt("rice.environment.random_loglevel", Logger.FINER);

    logger = env.getLogManager().getLogger(Replayer.class, null);

    //    env.getParameters().setInt("org.mpisws.p2p.transport.peerreview.replay_loglevel",
    // Logger.FINER);

    final Logger simLogger = env.getLogManager().getLogger(EventSimulator.class, null);

    final List<ReplayLayer<InetSocketAddress>> replayers =
        new ArrayList<ReplayLayer<InetSocketAddress>>();

    SocketPastryNodeFactory factory =
        new SocketPastryNodeFactory(
            new NodeIdFactory() {
              public Id generateNodeId() {
                return id;
              }
            },
            addr.getPort(),
            env) {

          //      @Override
          //      protected TransportLayer<MultiInetSocketAddress, ByteBuffer>
          // getPriorityTransportLayer(TransportLayer<MultiInetSocketAddress, ByteBuffer> trans,
          // LivenessProvider<MultiInetSocketAddress> liveness,
          // ProximityProvider<MultiInetSocketAddress> prox, PastryNode pn) {
          //        // get rid of the priorityLayer
          //        if
          // (params.getBoolean("org.mpisws.p2p.testing.transportlayer.replay.use_priority")) {
          //          return super.getPriorityTransportLayer(trans, liveness, prox, pn);
          //        } else {
          //          return trans;
          //        }
          //      }

          @Override
          public NodeHandle getLocalHandle(PastryNode pn, NodeHandleFactory nhf) {
            SocketNodeHandle ret = (SocketNodeHandle) super.getLocalHandle(pn, nhf);
            logger.log(ret.toStringFull());
            return ret;
          }

          @Override
          protected RandomSource cloneRandomSource(
              Environment rootEnvironment, Id nodeId, LogManager lman) {
            return rootEnvironment.getRandomSource();
          }

          @Override
          protected TransportLayer<InetSocketAddress, ByteBuffer> getWireTransportLayer(
              InetSocketAddress innermostAddress, PastryNode pn) throws IOException {
            Serializer<InetSocketAddress> serializer = new InetSocketAddressSerializer();

            HashProvider hashProv = new NullHashProvider();
            SecureHistoryFactory shFactory =
                new SecureHistoryFactoryImpl(hashProv, pn.getEnvironment());
            String logName = "0x" + id.toStringFull().substring(0, 6);
            SecureHistory hist = shFactory.open(logName, "r");

            ReplayLayer<InetSocketAddress> replay =
                new ReplayLayer<InetSocketAddress>(
                    serializer, hashProv, hist, addr, pn.getEnvironment());
            replay.registerEvent(Replayer.this, EVT_BOOT, EVT_SUBSCRIBE, EVT_PUBLISH);
            replayers.add(replay);
            return replay;
          }
        };

    // construct a node, passing the null boothandle on the first loop will
    // cause the node to start its own ring
    node = (PastryNode) factory.newNode();
    app = new MyScribeClient(node);

    ReplaySM sim = (ReplaySM) env.getSelectorManager();
    ReplayLayer<InetSocketAddress> replay = replayers.get(0);
    replay.makeProgress(); // get rid of INIT event
    sim.setVerifier(replay);

    sim.start();

    //    // this is an example of th enew way
    //    //PastryNode node = factory.newNode(nidFactory.generateNodeId());
    //    //node.getBootstrapper().boot(Collections.singleton(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);
    //
    //    // construct a new scribe application
    //    MyScribeClient app = new MyScribeClient(node);
    //
    //    // for all the rest just subscribe
    //    app.subscribe();

    // now, print the tree
    //    env.getTimeSource().sleep(5000);

    try {
      env.getTimeSource().sleep(55000);
    } catch (InterruptedException ie) {
      return;
    }
    env.destroy();
  }
示例#5
0
  public void init() {
    invokedInsert = false;
    messageId = Id.build("1111567890123456789012345678901234560023");

    content =
        new KoalaPiEntityContent(
            messageId, "what", false, "type", 4, NodeScope.AVAILABILITY_ZONE, "url", 1);
    continuation = mock(Continuation.class);

    builder = mock(MessageBuilder.class);
    when(builder.buildMessage())
        .thenReturn(new GCInsertMessage(-1, content, 0L, nodeHandle, Id.build("dest")));

    Logger logger = mock(Logger.class);

    LogManager logManager = mock(LogManager.class);
    when(logManager.getLogger(isA(Class.class), eq(instance))).thenReturn(logger);

    Parameters parameters = mock(Parameters.class);

    RandomSource randomSource = mock(RandomSource.class);

    Environment environment = mock(Environment.class);
    when(environment.getLogManager()).thenReturn(logManager);
    when(environment.getParameters()).thenReturn(parameters);
    when(environment.getRandomSource()).thenReturn(randomSource);
    TimeSource timesource = mock(TimeSource.class);
    when(timesource.currentTimeMillis()).thenReturn(System.currentTimeMillis());
    when(environment.getTimeSource()).thenReturn(timesource);

    Endpoint endpoint = mock(Endpoint.class);
    doAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                koalaDeserializer = (MessageDeserializer) invocation.getArguments()[0];
                return null;
              }
            })
        .when(endpoint)
        .setDeserializer(isA(MessageDeserializer.class));

    koalaIdFactory = mock(KoalaIdFactory.class);
    when(koalaIdFactory.buildIdFromToString(anyString()))
        .thenAnswer(
            new Answer<Id>() {
              @Override
              public Id answer(InvocationOnMock invocation) throws Throwable {
                return Id.build((String) invocation.getArguments()[0]);
              }
            });

    when(koalaIdFactory.buildId(anyString()))
        .thenAnswer(
            new Answer<Id>() {
              @Override
              public Id answer(InvocationOnMock invocation) throws Throwable {
                return Id.build((String) invocation.getArguments()[0]);
              }
            });

    node = mock(PastryNode.class);
    when(node.getEnvironment()).thenReturn(environment);
    when(node.buildEndpoint(isA(Application.class), eq(instance))).thenReturn(endpoint);
    when(node.getIdFactory()).thenReturn(koalaIdFactory);

    sentBackupContent = new ArrayList<KoalaMutableContent>();
    backupIds = new HashSet<rice.p2p.commonapi.Id>();

    storageManager = mock(StorageManager.class);
    koalaPiEntityFactory = mock(KoalaPiEntityFactory.class);
  }