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

The following examples show how to use org.jgroups.JChannel#connect() . 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: JGRpcOpener.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
/** Main processing method for the SocketOpener object */
public void run()
{
    try
    {

        //String props="UDP(mcast_addr=" + ilca.getUdpMulticastAddr() +
        // ";mcast_port=" + ilca.getUdpMulticastPort()+
        // "):PING:MERGE2(min_interval=5000;max_interval=10000):FD:STABLE:NAKACK:UNICAST:FLUSH:GMS:VIEW_ENFORCER:QUEUE";
        rpcCh = new JChannel( ilca.getJGChannelProperties() );
        rpcCh.setOpt( Channel.LOCAL, Boolean.FALSE );
        disp = new RpcDispatcher( rpcCh, null, null, ilcl );
        rpcCh.connect( groupName );

        if ( log.isInfoEnabled() )
        {
            log.info( "Is Connected = " + rpcCh.isConnected() );
        }

    }
    catch ( Exception e )
    {
        log.error( "Problem getting dispatcher.", e );
    }
}
 
Example 2
Source File: DistributedRemoteSubscriptionStorage.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Inject
public DistributedRemoteSubscriptionStorage(@Named("jgroups.config.file") String confFile)
    throws Exception {
  try {
    channel = new JChannel(confFile);
    this.lockService = new LockService(channel);
    channel.connect(CHANNEL_NAME);
    subscriptions = new ReplicatedHashMap<>(channel);
    subscriptions.setBlockingUpdates(true);
    subscriptions.start(5000);
  } catch (Exception e) {
    LOG.error("Unable to create distributed event subscriptions map.", e);
    throw e;
  }
}
 
Example 3
Source File: ReplicatedStateMachineTest.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("resource")
protected JChannel create(String name) throws Exception {
       RAFT raft=new RAFT().members(mbrs).raftId(name).stateMachine(new DummyStateMachine())
         .logClass("org.jgroups.protocols.raft.InMemoryLog").logName(name + "-" + CLUSTER);
       JChannel ch=new JChannel(Util.getTestStack(new ELECTION(), raft, new REDIRECT())).name(name);
       ch.connect(CLUSTER);
       return ch;
   }
 
Example 4
Source File: VoteTest.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
protected static JChannel create(String name, List<String> mbrs) throws Exception {
    RAFT raft=new RAFT().members(mbrs).raftId(name).stateMachine(new DummyStateMachine())
      .logClass("org.jgroups.protocols.raft.InMemoryLog").logName(name + "-" + CLUSTER);
    JChannel ch=new JChannel(Util.getTestStack(new ELECTION(), raft, new REDIRECT())).name(name);
    ch.connect(CLUSTER);
    return ch;
}
 
Example 5
Source File: DynamicMembershipTest.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
protected JChannel create(String name) throws Exception {
    RAFT raft=new RAFT().members(mbrs).raftId(name).stateMachine(new DummyStateMachine())
      .logClass("org.jgroups.protocols.raft.InMemoryLog").logName(name + "-" + CLUSTER);
    JChannel ch=new JChannel(Util.getTestStack(new ELECTION(), raft, new REDIRECT())).name(name);
    ch.connect(CLUSTER);
    return ch;
}
 
Example 6
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;
   			}
   		});
       }
}
 
Example 7
Source File: SolverServerService.java    From unitime with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	try {
		if (ApplicationProperty.SolverClusterEnabled.isFalse()) {
			iServer = new LocalSolverServer();
			
			iServer.start();
			
			iCourseSolverContainer = iServer.getCourseSolverContainer();
			iExamSolverContainer = iServer.getExamSolverContainer();
			iStudentSolverContainer = iServer.getStudentSolverContainer();
			iInstructorSchedulingContainer = iServer.getInstructorSchedulingContainer();
			iOnlineStudentSchedulingContainer = iServer.getOnlineStudentSchedulingContainer();
		} else {
			iChannel = (JChannel) new UniTimeChannelLookup().getJGroupsChannel(null);
			
			iServer = new SolverServerImplementation(true, iChannel);
			
			iChannel.connect("UniTime:rpc");
			
			iServer.start();
			
			iCourseSolverContainer = new SolverContainerWrapper<SolverProxy>(
					((SolverServerImplementation)iServer).getDispatcher(),
					(RemoteSolverContainer<SolverProxy>) iServer.getCourseSolverContainer(), true);
			iExamSolverContainer = new SolverContainerWrapper<ExamSolverProxy>(
					((SolverServerImplementation)iServer).getDispatcher(),
					(RemoteSolverContainer<ExamSolverProxy>) iServer.getExamSolverContainer(), true);
			iStudentSolverContainer = new SolverContainerWrapper<StudentSolverProxy>(
					((SolverServerImplementation)iServer).getDispatcher(),
					(RemoteSolverContainer<StudentSolverProxy>) iServer.getStudentSolverContainer(), true);
			iInstructorSchedulingContainer = new SolverContainerWrapper<InstructorSchedulingProxy>(
					((SolverServerImplementation)iServer).getDispatcher(),
					(RemoteSolverContainer<InstructorSchedulingProxy>) iServer.getInstructorSchedulingContainer(), true);
			iOnlineStudentSchedulingContainer = new SolverContainerWrapper<OnlineSectioningServer>(
					((SolverServerImplementation)iServer).getDispatcher(),
					(RemoteSolverContainer<OnlineSectioningServer>) iServer.getOnlineStudentSchedulingContainer(), false);
		}
	} catch (Exception e) {
		sLog.fatal("Failed to start solver server: " + e.getMessage(), e);
	}
}
 
Example 8
Source File: Main.java    From java-course-ee with MIT License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    String name = args[0];

    if (name == null) {
        System.out.println("Provide name as a parameter");
        return;
    }

    JChannel channel = new JChannel();
    channel.setDiscardOwnMessages(false);
    channel.setName(name);
    channel.connect("NodeCluster");
    NodeReceiverAdapter receiver = new NodeReceiverAdapter();
    channel.setReceiver(receiver);

    System.out.println("use 'all' for 'who' to send message to all current cluster members");

    while (true) {
        System.out.print("(who:message) >> ");
        BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
        String command = inputReader.readLine();

        int separator = command.indexOf(':');
        if (separator == -1) {
            System.out.println("wrong input");
            continue;
        }
        String who = command.substring(0, separator);
        Address dest = null;
        if (!who.equals("all")) {
            final List<Address> members = channel.getView().getMembers();
            for (Address member : members) {
                if (member.toString().equals(who)) {
                    dest = member;
                    break;
                }
            }
        }

        String message = command.substring(separator + 1);
        channel.send(new Message(dest, message));
    }
}