public void tearDown() throws Exception {
   super.tearDown();
   if (ch2 != null) {
     ch2.close();
     ch2 = null;
   }
   if (ch1 != null) {
     ch1.close();
     ch1 = null;
   }
 }
 private static void closeSilently(JChannel channel) {
   try {
     channel.close();
   } catch (Exception e) {
     // ignore
   }
 }
Пример #3
0
  private void sendMessage() {
    try {
      /**
       * 参数里指定Channel使用的协议栈,如果是空的,则使用默认的协议栈, 位于JGroups包里的udp.xml。参数可以是一个以冒号分隔的字符串,
       * 或是一个XML文件,在XML文件里定义协议栈。
       */
      logger.warn("发送监控同步数据通知");

      Properties prop = SystemPropertiesUtils.getProp();
      String hostName = NetUtils.getLocalHost();
      prop.put("node.ip", NetUtils.getIpByHost(hostName));
      prop.put("node.host", hostName);
      prop.put("install.path", getInstallPath());
      // 创建一个通道
      JChannel channel = new JChannel();
      // 加入一个群
      channel.connect("MonitorContainer");
      // 发送事件
      // 这里的Message的第一个参数是发送端地址
      // 第二个是接收端地址
      // 第三个是发送的字符串
      // 具体参见jgroup send API
      Message msg = new Message(null, null, prop);
      // 发送
      channel.send(msg);
      // 关闭通道
      channel.close();
    } catch (Exception e) {
      logger.error(e.getMessage());
    }
  }
  @Override
  public void run() {
    try {
      log.info("Hello from Cluster microservice provider!");

      channel = new JChannel((String) context.getProperties().get(CLUSTER_CONFIGURATION));
      channel.setReceiver(receiver);

      channel.connect((String) context.getProperties().get(CLUSTER_GROUP));

      channel.send(new Message(null, "Holáryjou!"));

      try {
        while (!Thread.currentThread().isInterrupted()) {
          Thread.sleep(1000);
        }
      } catch (InterruptedException ie) {
        Utils.shutdownLog(log, ie);
      } finally {
        channel.close();
      }
    } catch (Exception e) {
      log.error("Cluster microservice provider failed: ", e);
    }
  }
Пример #5
0
 /**
  * 启动连接。
  *
  * @throws Exception
  */
 private void start() throws Exception {
   channle = new JChannel();
   channle.setReceiver(this);
   channle.connect("ChatCluster");
   channle.getState(null, 10000);
   eventloop();
   channle.close();
 }
 @AfterMethod
 protected void closeSecondChannel() {
   if (c2 != null) {
     d2.stop();
     c2.close();
     Util.sleep(500);
   }
 }
Пример #7
0
  public void receive(Message msg) {
    String recievedMsg = msg.getObject().toString();
    System.out.println(msg.getSrc() + ": " + recievedMsg);

    if (recievedMsg.contains("Is any body out there?")) {
      // sendMessage("I am here!");
      System.out.println("Recieved it!");
      channel.close();
    }
  }
Пример #8
0
 /** Leave Group and close JWhiteBoard */
 public void stop() {
   if (!noChannel) {
     try {
       channel.close();
     } catch (Exception ex) {
       System.err.println(ex);
     }
   }
   mainFrame.setVisible(false);
   mainFrame.dispose();
 }
Пример #9
0
  void runClient() throws Exception {
    IpAddress addr;
    Message msg;
    String line;
    BufferedReader reader;

    ch.connect(null); // unicast channel
    addr = new IpAddress(host, port);
    reader = new BufferedReader(new InputStreamReader(System.in));

    while (true) {
      System.out.print("> ");
      line = reader.readLine();
      if (line.startsWith("quit") || line.startsWith("exit")) {
        ch.close();
        return;
      }
      msg = new Message(addr, null, line);
      ch.send(msg);
    }
  }
  @Test(timeout = 300000)
  public void testHashChangeNotification() throws Exception {
    connector1.connect(10);
    connector2.connect(10);

    // wait for both connectors to have the same view
    waitForConnectorSync();

    // connector 1 joined
    ConsistentHash notify1 = hashChangeListener.notifications.poll(5, TimeUnit.SECONDS);

    // connector 2 joined
    ConsistentHash notify2 = hashChangeListener.notifications.poll(5, TimeUnit.SECONDS);
    // Self and other node have joined
    assertEquals(connector1.getConsistentHash(), notify2);

    channel2.close();

    // Other node has left
    ConsistentHash notify3 = hashChangeListener.notifications.poll(5, TimeUnit.SECONDS);
    assertEquals(connector1.getConsistentHash(), notify3);
  }
Пример #11
0
  public void eventLoop() throws Exception {
    int c;

    while (true) {
      System.out.print(
          "[1] Send msgs [2] Print view [3] Print conns [5] Trash all conns"
              + "\n[6] Set sender threads ("
              + num_threads
              + ") [7] Set num msgs ("
              + num_msgs
              + ") "
              + "[8] Set msg size ("
              + Util.printBytes(msg_size)
              + ")"
              + "\n[o] Toggle OOB ("
              + oob
              + ") [b] Toggle dont_bundle ("
              + dont_bundle
              + ")\n[q] Quit\n");
      System.out.flush();
      c = System.in.read();
      switch (c) {
        case -1:
          break;
        case '1':
          sendMessages();
          break;
        case '2':
          printView();
          break;
        case '3':
          printConnections();
          break;
        case '5':
          removeAllConnections();
          break;
        case '6':
          setSenderThreads();
          break;
        case '7':
          setNumMessages();
          break;
        case '8':
          setMessageSize();
          break;
        case 'o':
          oob = !oob;
          System.out.println("oob=" + oob);
          break;
        case 'b':
          dont_bundle = !dont_bundle;
          System.out.println("dont_bundle = " + dont_bundle);
          break;
        case 'q':
          channel.close();
          return;
        default:
          break;
      }
    }
  }
 @AfterClass
 protected void tearDown() throws Exception {
   d1.stop();
   c1.close();
   Util.sleep(500);
 }
Пример #13
0
  public void eventLoop() throws Throwable {
    int c;

    while (true) {
      c =
          Util.keyPress(
              "[1] Send msgs [2] Print view [3] Print conns "
                  + "[4] Trash conn [5] Trash all conns"
                  + "\n[6] Set sender threads ("
                  + num_threads
                  + ") [7] Set num msgs ("
                  + num_msgs
                  + ") "
                  + "[8] Set msg size ("
                  + Util.printBytes(msg_size)
                  + ")"
                  + " [9] Set anycast count ("
                  + anycast_count
                  + ")"
                  + "\n[o] Toggle OOB ("
                  + oob
                  + ") [s] Toggle sync ("
                  + sync
                  + ") [r] Set read percentage ("
                  + f.format(read_percentage)
                  + ")"
                  + "\n[q] Quit\n");
      switch (c) {
        case -1:
          break;
        case '1':
          try {
            startBenchmark();
          } catch (Throwable t) {
            System.err.println(t);
          }
          break;
        case '2':
          printView();
          break;
        case '3':
          printConnections();
          break;
        case '4':
          removeConnection();
          break;
        case '5':
          removeAllConnections();
          break;
        case '6':
          setSenderThreads();
          break;
        case '7':
          setNumMessages();
          break;
        case '8':
          setMessageSize();
          break;
        case '9':
          setAnycastCount();
          break;
        case 'o':
          boolean new_value = !oob;
          disp.callRemoteMethods(null, new MethodCall(SET_OOB, new_value), RequestOptions.SYNC());
          break;
        case 's':
          boolean new_val = !sync;
          disp.callRemoteMethods(null, new MethodCall(SET_SYNC, new_val), RequestOptions.SYNC());
          break;
        case 'r':
          setReadPercentage();
          break;
        case 'q':
          channel.close();
          return;
        case '\n':
        case '\r':
          break;
        default:
          break;
      }
    }
  }
 @Override
 public void close() {
   channel.close();
 }
Пример #15
0
 protected void close() {
   if (iChannel != null && iChannel.isConnected()) iChannel.disconnect();
   if (iChannel != null && iChannel.isOpen()) iChannel.close();
   OnlineSectioningLogger.stopLogger();
   HibernateUtil.closeHibernate();
 }
Пример #16
0
  protected void startServer() {
    final Session session =
        Session.getSessionUsingInitiativeYearTerm(
            ApplicationProperties.getProperty("initiative", "woebegon"),
            ApplicationProperties.getProperty("year", "2010"),
            ApplicationProperties.getProperty("term", "Fal"));

    boolean remote = "true".equalsIgnoreCase(ApplicationProperties.getProperty("remote", "true"));

    if (session == null) {
      sLog.error(
          "Academic session not found, use properties initiative, year, and term to set academic session.");
      System.exit(0);
    } else {
      sLog.info("Session: " + session);
    }

    iSessionId = session.getUniqueId();

    OnlineSectioningLogger.getInstance().setEnabled(false);

    if (remote) {
      try {
        iChannel =
            new JChannel(
                JGroupsUtils.getConfigurator(
                    ApplicationProperty.SolverClusterConfiguration.value()));
        iChannel.setUpHandler(new MuxUpHandler());

        iSolverServer = new DummySolverServer(iChannel);

        iChannel.connect("UniTime:rpc");
        iChannel.getState(null, 0);

        if (getServer() == null) throw new Exception(session.getLabel() + " is not available");
      } catch (Exception e) {
        sLog.error("Failed to access the solver server: " + e.getMessage(), e);
        if (iChannel != null && iChannel.isConnected()) iChannel.disconnect();
        if (iChannel != null && iChannel.isOpen()) iChannel.close();
        System.exit(0);
      }
    } else {
      iServer =
          new InMemoryServer(
              new OnlineSectioningServerContext() {
                @Override
                public boolean isWaitTillStarted() {
                  return true;
                }

                @Override
                public EmbeddedCacheManager getCacheManager() {
                  return null;
                }

                @Override
                public Long getAcademicSessionId() {
                  return session.getUniqueId();
                }

                @Override
                public LockService getLockService() {
                  return null;
                }
              });
    }
  }
Пример #17
0
 public void exitCluster() {
   channel.close();
 }
 public void stop() {
   channel.close();
 }
Пример #19
0
 @AfterMethod
 public void cleanup() {
   a.close();
   b.close();
 }