/**
  * Connects this member to the cluster using the given <code>loadFactor</code>. The <code>
  * loadFactor</code> defines the (approximate) relative load that this member will receive.
  *
  * <p>A good default value is 100, which will give this member 100 nodes on the distributed hash
  * ring. Giving all members (proportionally) lower values will result in a less evenly distributed
  * hash.
  *
  * @param loadFactor The load factor for this node.
  * @throws ConnectionFailedException when an error occurs while connecting
  */
 public synchronized void connect(int loadFactor) throws ConnectionFailedException {
   this.currentLoadFactor = loadFactor;
   Assert.isTrue(loadFactor >= 0, "Load Factor must be a positive integer value.");
   Assert.isTrue(
       channel.getReceiver() == null || channel.getReceiver() == messageReceiver,
       "The given channel already has a receiver configured. "
           + "Has the channel been reused with other Connectors?");
   try {
     channel.setReceiver(messageReceiver);
     if (channel.isConnected() && !clusterName.equals(channel.getClusterName())) {
       throw new AxonConfigurationException(
           "The Channel that has been configured with this JGroupsConnector "
               + "is already connected to another cluster.");
     } else if (channel.isConnected()) {
       // we need to fetch state now that we have attached our MessageReceiver
       channel.getState(null, 10000);
     } else {
       // we need to connect. This will automatically fetch state as well.
       channel.connect(clusterName, null, 10000);
     }
     updateMembership();
   } catch (Exception e) {
     joinedCondition.markJoined(false);
     channel.disconnect();
     throw new ConnectionFailedException("Failed to connect to JGroupsConnectorFactoryBean", e);
   }
 }
 public void testSASLDigestMD5() throws Exception {
   a = createChannel("A", "DIGEST-MD5", "jack");
   b = createChannel("B", "DIGEST-MD5", "jack");
   a.connect("SaslTest");
   b.connect("SaslTest");
   assertTrue(b.isConnected());
 }
 private void updateMembership() throws MembershipUpdateFailedException {
   try {
     if (channel.isConnected()) {
       channel.send(
           new Message(
                   null,
                   new JoinMessage(currentLoadFactor, new HashSet<String>(supportedCommandTypes)))
               .setFlag(Message.Flag.RSVP));
     }
   } catch (Exception e) {
     throw new MembershipUpdateFailedException(
         "Failed to dispatch Join message to Distributed Command Bus Members", e);
   }
 }
 public void testSASLDigestMD5Merge() throws Exception {
   a = createChannel("A", "DIGEST-MD5", "jack");
   b = createChannel("B", "DIGEST-MD5", "jack");
   a.connect("SaslTest");
   b.connect("SaslTest");
   assertTrue(b.isConnected());
   print(a, b);
   createPartitions(a, b);
   print(a, b);
   assertTrue(checkViewSize(1, a, b));
   dropDiscard(a, b);
   mergePartitions(a, b);
   for (int i = 0; i < 10 && !checkViewSize(2, a, b); i++) {
     Util.sleep(500);
   }
   assertTrue(viewContains(a.getView(), a, b));
   assertTrue(viewContains(b.getView(), a, b));
 }
 protected void close() {
   if (iChannel != null && iChannel.isConnected()) iChannel.disconnect();
   if (iChannel != null && iChannel.isOpen()) iChannel.close();
   OnlineSectioningLogger.stopLogger();
   HibernateUtil.closeHibernate();
 }
  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;
                }
              });
    }
  }