private int closeStream(ReactorChannel chnl, int streamId, ReactorErrorInfo errorInfo) { if(chnl.state() == State.UP) { //get a buffer for the item close TransportBuffer msgBuf = chnl.getBuffer(TRANSPORT_BUFFER_SIZE_CLOSE, false, errorInfo); if (msgBuf == null) return ReactorReturnCodes.FAILURE; //encode item close closeMessage.clear(); closeMessage.streamId(streamId); encIter.clear(); encIter.setBufferAndRWFVersion(msgBuf, chnl.majorVersion(), chnl.minorVersion()); int ret = closeMessage.encode(encIter); if (ret != CodecReturnCodes.SUCCESS) { System.out.println("encodeMarketByOrderClose(): Failed <" + CodecReturnCodes.toString(ret) + ">"); } return chnl.submit(msgBuf, submitOptions, errorInfo); } return ReactorReturnCodes.SUCCESS; }
SelectionKey key = reactorChannel.oldSelectableChannel().keyFor(_selector); if (key != null) reactorChannel.selectableChannel().register(_selector, options, reactorChannel); if (reactorChannel.state() != State.CLOSED && reactorChannel.state() != State.DOWN && reactorChannel.state() != State.DOWN_RECONNECTING) reactorChannel.state(State.DOWN);
void rsslReactorChannel(ReactorChannel rsslReactorChannel) { _rsslReactorChannel = rsslReactorChannel; _majorVersion = rsslReactorChannel.majorVersion(); _minorVersion = rsslReactorChannel.minorVersion(); }
int sendRequestReject(ReactorChannel chnl, int streamId, LoginRejectReason reason, ReactorErrorInfo errorInfo) { // get a buffer for the login request reject status */ TransportBuffer msgBuf = chnl.getBuffer(REJECT_MSG_SIZE, false, errorInfo); if (msgBuf == null) { return CodecReturnCodes.FAILURE; } int ret = encodeRequestReject(chnl, streamId, reason, msgBuf, errorInfo); if (ret != CodecReturnCodes.SUCCESS) { return ret; } return chnl.submit(msgBuf, _submitOptions, errorInfo); }
/** * Release channel buffer. * * @param buffer the buffer * @param error the error * @return the int */ int releaseChannelBuffer(TransportBuffer buffer, Error error) { assert(_reactorChannel.tunnelStreamManager().reactorChannel().channel() != null); Channel channel = _reactorChannel.tunnelStreamManager().reactorChannel().channel(); return channel.releaseBuffer(buffer, error); }
ProviderSession provSession = (ProviderSession)reactorChannel.userSpecObj(); if (reactorChannel.ioctl(IoctlCodes.HIGH_WATER_MARK, ProviderPerfConfig.highWaterMark(), _errorInfo) != TransportReturnCodes.SUCCESS) reactorChannel.close(_errorInfo); reactorChannel.selectableChannel().register(_selector, SelectionKey.OP_READ, reactorChannel); if (reactorChannel.info(_reactorChannnelInfo, _errorInfo) != TransportReturnCodes.SUCCESS) reactorChannel.close(_errorInfo); reactorChannel.selectableChannel(), _reactorChannnelInfo.channelInfo().maxFragmentSize(), ProviderPerfConfig.packingBufferLength()); System.exit(-1); provSession.clientChannelInfo().channel = reactorChannel.channel(); provSession.clientChannelInfo().parentQueue = _channelHandler.activeChannelList(); provSession.clientChannelInfo().parentQueue.add(provSession.clientChannelInfo()); reactorChannel.close(_errorInfo); + event.reactorChannel().oldSelectableChannel() + " New Channel: " + event.reactorChannel().selectableChannel()); SelectionKey key = event.reactorChannel().oldSelectableChannel().keyFor(_selector); key.cancel();
Server server = (Server)reactorChannel.userSpecObj(); System.out.println("Server " + server.selectableChannel() + ": New client on Channel " + reactorChannel.channel().selectableChannel()); reactorChannel.selectableChannel().register(selector, SelectionKey.OP_READ, reactorChannel); if (reactorChannel.ioctl(IoctlCodes.SYSTEM_WRITE_BUFFERS, sendBufSize, errorInfo) != TransportReturnCodes.SUCCESS) if (reactorChannel.ioctl(IoctlCodes.SYSTEM_READ_BUFFERS, rcvBufSize, errorInfo) != TransportReturnCodes.SUCCESS) + reactorChannel.oldSelectableChannel() + " New Channel: " + reactorChannel.selectableChannel()); SelectionKey key = event.reactorChannel().oldSelectableChannel().keyFor(selector); if (key != null) key.cancel(); reactorChannel.selectableChannel().register(selector, SelectionKey.OP_READ, reactorChannel); if (event.reactorChannel().selectableChannel() != null) System.out.println("\nConnection down: Channel " + event.reactorChannel().selectableChannel()); else System.out.println("\nConnection down");
@Override public int defaultMsgCallback(ReactorMsgEvent event) ChannelInfo chnlInfo = (ChannelInfo)event.reactorChannel().userSpecObj(); Msg msg = event.msg(); if (event.reactorChannel().selectableChannel() != null) SelectionKey key = event.reactorChannel().selectableChannel().keyFor(selector); if (key != null) key.cancel(); chnlInfo.reactorChannel.close(errorInfo); event.reactorChannel().majorVersion(), event.reactorChannel().minorVersion());
ChannelInfo chnlInfo = (ChannelInfo)event.reactorChannel().userSpecObj(); event.reactorChannel().selectableChannel().register(selector, SelectionKey.OP_READ, event.reactorChannel()); if (event.reactorChannel().ioctl(IoctlCodes.SYSTEM_WRITE_BUFFERS, sendBufSize, errorInfo) != TransportReturnCodes.SUCCESS) if (event.reactorChannel().ioctl(IoctlCodes.SYSTEM_READ_BUFFERS, rcvBufSize, errorInfo) != TransportReturnCodes.SUCCESS) + event.reactorChannel().oldSelectableChannel() + " New Channel: " + event.reactorChannel().selectableChannel()); SelectionKey key = event.reactorChannel().oldSelectableChannel().keyFor(selector); if (key != null) key.cancel(); event.reactorChannel().selectableChannel().register(selector, SelectionKey.OP_READ, event.reactorChannel()); if (event.reactorChannel().selectableChannel() != null) System.out.println("\nConnection down reconnecting: Channel " + event.reactorChannel().selectableChannel()); else System.out.println("\nConnection down reconnecting"); if (event.reactorChannel().selectableChannel() != null) SelectionKey key = event.reactorChannel().selectableChannel().keyFor(selector);
(chnlInfo.reactorChannel.state() != ReactorChannel.State.UP && chnlInfo.reactorChannel.state() != ReactorChannel.State.READY)) if (chnlInfo.reactorChannel.submit(loginRequest, submitOptions, errorInfo) != CodecReturnCodes.SUCCESS) while ((ret = reactorChnl.dispatch(dispatchOptions, errorInfo)) > 0) {} if (ret == ReactorReturnCodes.FAILURE) if (reactorChnl.state() != ReactorChannel.State.CLOSED && reactorChnl.state() != ReactorChannel.State.DOWN_RECONNECTING) if (chnlInfo.reactorChannel != null && chnlInfo.reactorChannel.state() == ReactorChannel.State.READY && chnlInfo.loginRefresh.state().streamState() == StreamStates.OPEN && chnlInfo.loginRefresh.state().dataState() == DataStates.OK )
_reactor.reactorChannel().selectableChannel().register(_selector, SelectionKey.OP_READ, _reactor.reactorChannel()); while ((ret = reactorChnl.dispatch(_dispatchOptions, _errorInfo)) > 0 && !shutdown()) {} if (ret == ReactorReturnCodes.FAILURE) if (reactorChnl.state() != ReactorChannel.State.CLOSED && reactorChnl.state() != ReactorChannel.State.DOWN_RECONNECTING) reactorChnl.close(_errorInfo); System.exit(CodecReturnCodes.FAILURE);
return ReactorReturnCodes.FAILURE; else if (event == null) return reactor().populateErrorInfo(errorInfo, ReactorReturnCodes.FAILURE, "ReactorChannel.acceptTunnelStream", "TunnelStreamRequestEvent cannot be null"); else if (options == null) return reactor().populateErrorInfo(errorInfo, ReactorReturnCodes.FAILURE, "ReactorChannel.acceptTunnelStream", "TunnelStreamAcceptOptions cannot be null"); _tunnelStreamRejectOptions.expectedClassOfService(_defaultClassOfService); rejectTunnelStream(event, _tunnelStreamRejectOptions, errorInfo); _tunnelStreamRejectOptions.expectedClassOfService(_defaultClassOfService); rejectTunnelStream(event, _tunnelStreamRejectOptions, errorInfo); while ((ret = submit(refreshMsg, _reactorSubmitOptions, errorInfo)) < ReactorReturnCodes.SUCCESS) if ((ret = info(_reactorChannelInfo, errorInfo)) < ReactorReturnCodes.SUCCESS) if ((ret = ioctl(IoctlCodes.NUM_GUARANTEED_BUFFERS, newNumberOfBuffers, errorInfo)) < ReactorReturnCodes.SUCCESS) if ((ret = checkTunnelManagerEvents(errorInfo)) != ReactorReturnCodes.SUCCESS) return ret;
int processGenericMsg(Msg rsslMsg, ReactorChannel rsslReactorChannel, RDMLoginMsgEvent event) { if (_loginItemList == null) return ReactorCallbackReturnCodes.SUCCESS; if (_genericMsg == null) _genericMsg = new GenericMsgImpl(); _genericMsg.decode(rsslMsg, rsslReactorChannel.majorVersion(), rsslReactorChannel.minorVersion(), ((ChannelInfo)event.reactorChannel().userSpecObj()).rsslDictionary()); _loginItemLock.lock(); int itemSize = _loginItemList.size(); for (int idx = 0; idx < itemSize; ++idx) { _eventImpl._item = _loginItemList.get(idx); notifyOnAllMsg(_genericMsg); notifyOnGenericMsg(); } _loginItemLock.unlock(); return ReactorCallbackReturnCodes.SUCCESS; }
return ReactorReturnCodes.FAILURE; else if (event == null) return reactor().populateErrorInfo(errorInfo, ReactorReturnCodes.FAILURE, "ReactorChannel.rejectTunnelStream", "TunnelStreamRequestEvent cannot be null"); else if (options == null) return reactor().populateErrorInfo(errorInfo, ReactorReturnCodes.FAILURE, "ReactorChannel.rejectTunnelStream", "options cannot be null"); while ((ret = submit(statusMsg, _reactorSubmitOptions, errorInfo)) < ReactorReturnCodes.SUCCESS) if ((ret = info(_reactorChannelInfo, errorInfo)) < ReactorReturnCodes.SUCCESS) if ((ret = ioctl(IoctlCodes.NUM_GUARANTEED_BUFFERS, newNumberOfBuffers, errorInfo)) < ReactorReturnCodes.SUCCESS)
int initializeReactor(ReactorErrorInfo errorInfo) { try { // create SelectableBiDirectionalQueue _workerQueue = new SelectableBiDirectionalQueue(); // create a new ReactorChannel and populate with the readChannel // side of our _workerQueue. _reactorChannel = ReactorFactory.createReactorChannel(); _reactorChannel.reactor(this); _reactorChannel.userSpecObj(this); _reactorChannel.selectableChannel(_workerQueue.readChannel()); // create the worker thread. _worker = new Worker(_reactorChannel, _workerQueue.remote()); _esWorker = Executors.newSingleThreadExecutor(); _esWorker.execute(_worker); } catch (RejectedExecutionException | NullPointerException e) { return populateErrorInfo(errorInfo, ReactorReturnCodes.FAILURE, "Reactor.initializeReactor", "failed to initialize the Worker, exception=" + e.getLocalizedMessage()); } return ReactorReturnCodes.SUCCESS; }
private void read(ReactorChannel reactorChannel) { int ret; /* read until no more to read */ if (reactorChannel != null) { while ((ret = reactorChannel.dispatch(_dispatchOptions, _errorInfo)) > 0) {} if (ret == ReactorReturnCodes.FAILURE) { if (reactorChannel.state() != ReactorChannel.State.CLOSED && reactorChannel.state() != ReactorChannel.State.DOWN_RECONNECTING) { System.out.println("ReactorChannel dispatch failed: " + ret + "(" + _errorInfo.error().text() + ")"); closeReactor(); System.exit(ReactorReturnCodes.FAILURE); } } } }
theReactorChannel.selectableChannel().register(selector, SelectionKey.OP_READ, theReactorChannel); assertNotNull(event); assertEquals(ReactorChannelEventTypes.CHANNEL_READY, event.eventType()); assertTrue(event.reactorChannel().userSpecObj().equals("userSpecObject: " + serverPort)); assertEquals(0, rc.dispatch(dispatchOptions, errorInfo)); assertNotNull(event); assertEquals(ReactorChannelEventTypes.CHANNEL_READY, event.eventType()); assertTrue(event.reactorChannel().userSpecObj().equals("userSpecObject: " + serverPortBackup)); SelectionKey key = theReactorChannel.selectableChannel().keyFor(selector); key.cancel();
_rsslErrorInfo.clear(); int retCode = reactorChannel.submit(_directoryStatus, _rsslSubmitOptions, _rsslErrorInfo); ClientSession clientSession = (ClientSession)reactorChannel.userSpecObj();
rc.channel().selectableChannel().register(_selector, SelectionKey.OP_READ, rc); case ReactorChannelEventTypes.CHANNEL_DOWN_RECONNECTING: _channelDownEventCount++; if (rc.selectableChannel() != null) SelectionKey key = rc.selectableChannel().keyFor(_selector); if (key != null) key.cancel();