Java Code Examples for org.jgroups.JChannel#isConnected()

The following examples show how to use org.jgroups.JChannel#isConnected() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VoteTest.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
protected static Address leader(long timeout, long interval, JChannel ... channels) {
    long target_time=System.currentTimeMillis() + timeout;
    while(System.currentTimeMillis() <= target_time) {
        for(JChannel ch : channels) {
            if(ch.isConnected() && raft(ch).leader() != null)
                return raft(ch).leader();
        }
        Util.sleep(interval);
    }
    return null;
}
 
Example 2
Source File: VoteTest.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
protected static int nonLeader(JChannel ... channels) {
    for(int i=channels.length-1; i >= 0; i--) {
        JChannel ch=channels[i];
        if(!ch.isConnected())
            continue;
        if(!raft(ch).leader().equals(ch.getAddress()))
            return i;
    }
    return -1;
}
 
Example 3
Source File: DynamicMembershipTest.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
protected static Address leader(long timeout, long interval, JChannel ... channels) {
    long target_time=System.currentTimeMillis() + timeout;
    while(System.currentTimeMillis() <= target_time) {
        for(JChannel ch : channels) {
            if(ch.isConnected() && raft(ch).leader() != null)
                return raft(ch).leader();
        }
        Util.sleep(interval);
    }
    return null;
}
 
Example 4
Source File: OnlineSectioningTestFwk.java    From unitime with Apache License 2.0 4 votes vote down vote up
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", "false"));

       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 false;
   			}
   			
   			@Override
   			public EmbeddedCacheManager getCacheManager() {
   				return null;
   			}
   			
   			@Override
   			public Long getAcademicSessionId() {
   				return session.getUniqueId();
   			}

   			@Override
   			public LockService getLockService() {
   				return null;
   			}
   		});
       }
}