@Override public void onConnected(GridNioSession ses) { HadoopProcessDescriptor desc = ses.meta(PROCESS_META); assert desc != null : "Received connected notification without finished handshake: " + ses; }
/** {@inheritDoc} */ @Override public void onMessage(GridNioSession ses, HadoopMessage msg) { notifyListener(ses.<HadoopProcessDescriptor>meta(PROCESS_META), msg); if (msgQueueLimit > 0) { GridNioMessageTracker tracker = ses.meta(TRACKER_META); assert tracker != null : "Missing tracker for limited message queue: " + ses; tracker.run(); } } };
/** * Returns marshaller. * * @return Marshaller. */ protected GridClientMarshaller marshaller(GridNioSession ses) { GridClientMarshaller marsh = ses.meta(MARSHALLER.ordinal()); assert marsh != null; return marsh; }
/** {@inheritDoc} */ @Override public byte[] decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException { ClientListenerNioServerBuffer nioBuf = ses.meta(BUF_META_KEY); // Decode for a given session is called per one thread, so there should not be any concurrency issues. // However, we make some additional checks. if (nioBuf == null) { nioBuf = new ClientListenerNioServerBuffer(); ClientListenerNioServerBuffer old = ses.addMeta(BUF_META_KEY, nioBuf); assert old == null; } boolean checkHandshake = ses.meta(ClientListenerNioListener.CONN_CTX_HANDSHAKE_PASSED) == null; return nioBuf.read(buf, checkHandshake); }
@Override public void onSessionIdleTimeout(GridNioSession ses) { idleEvt.compareAndSet(null, ses.<String>meta(IDLE_META_NAME)); } };
@Override public GridNioFuture<Boolean> onSessionClose(GridNioSession ses) { closeEvt.compareAndSet(null, ses.<String>meta(CLOSE_META_NAME)); return null; }
@Override public void onConnected(GridNioSession ses) { connectedEvt.compareAndSet(null, ses.<String>meta(OPENED_META_NAME)); }
/** {@inheritDoc} */ @Override public List<String> getConnections() { Collection<? extends GridNioSession> sessions = srv.sessions(); List<String> res = new ArrayList<>(sessions.size()); for (GridNioSession ses : sessions) { ClientListenerConnectionContext connCtx = ses.meta(CONN_CTX_META_KEY); if (connCtx == null || ses.closeTime() != 0) continue; // Skip non-initialized or closed session. String desc = clientConnectionDescription(ses, connCtx); res.add(desc); } return res; }
@Override public void onSessionWriteTimeout(GridNioSession ses) { writeTimeoutEvt.compareAndSet(null, ses.<String>meta(WRITE_TIMEOUT_META_NAME)); }
@Override public GridNioFuture<?> onSessionWrite(GridNioSession ses, Object msg, boolean fut, IgniteInClosure<IgniteException> ackC) { sndEvt.compareAndSet(null, ses.<String>meta(MESSAGE_WRITE_META_NAME)); sndMsgObj.compareAndSet(null, msg); return null; }
/** {@inheritDoc} */ @Override public GridNioFuture<?> onSessionWrite(GridNioSession ses, Object msg, boolean fut, IgniteInClosure<IgniteException> ackC) throws IgniteCheckedException { if (ses.meta(PROCESS_META) == null && !(msg instanceof ProcessHandshakeMessage)) log.warning("Writing message before handshake has finished [ses=" + ses + ", msg=" + msg + ']'); return proceedSessionWrite(ses, msg, fut, ackC); }
@Override public void onMessage(GridNioSession ses, Object msg) { msgEvt.compareAndSet(null, ses.<String>meta(MESSAGE_RECEIVED_META_NAME)); rcvdMsgObj.compareAndSet(null, (ByteBuffer)msg); }
@Override public void onDisconnected(GridNioSession ses, @Nullable Exception e) { disconnectedEvt.compareAndSet(null, ses.<String>meta(CLOSED_META_NAME)); }
/** {@inheritDoc} */ @Override public byte[] decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException { GridNioServerBuffer nioBuf = ses.meta(BUF_META_KEY); // Decode for a given session is called per one thread, so there should not be any concurrency issues. // However, we make some additional checks. if (nioBuf == null) { nioBuf = new GridNioServerBuffer(); GridNioServerBuffer old = ses.addMeta(BUF_META_KEY, nioBuf); assert old == null; } return nioBuf.read(buf); }
/** * Appends parameter of this filter to a meta with specified name. * * @param ses Session. * @param metaKey Meta key. */ private void chainMeta(GridNioSession ses, int metaKey) { String att = ses.meta(metaKey); att = (att == null ? "" : att) + param; ses.addMeta(metaKey, att); } }
/** {@inheritDoc} */ @Override public byte[] decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException { GridNioDelimitedBuffer nioBuf = ses.meta(BUF_META_KEY); // Decode for a given session is called per one thread, so there should not be any concurrency issues. // However, we make some additional checks. if (nioBuf == null) { nioBuf = new GridNioDelimitedBuffer(delim); GridNioDelimitedBuffer old = ses.addMeta(BUF_META_KEY, nioBuf); assert old == null; } return nioBuf.read(buf); }
@Override public MessageWriter writer(GridNioSession ses) throws IgniteCheckedException { if (formatter == null) formatter = getSpiContext().messageFormatter(); assert formatter != null; ConnectionKey connKey = ses.meta(CONN_IDX_META); return connKey != null ? formatter.writer(connKey.nodeId()) : null; } };
@Override public MessageReader reader(GridNioSession ses, MessageFactory msgFactory) throws IgniteCheckedException { if (formatter == null) formatter = getSpiContext().messageFormatter(); assert formatter != null; ConnectionKey connKey = ses.meta(CONN_IDX_META); return connKey != null ? formatter.reader(connKey.nodeId(), msgFactory) : null; } };
/** {@inheritDoc} */ @Override public void onDisconnected(GridNioSession ses, @Nullable Exception e) { ClientListenerConnectionContext connCtx = ses.meta(CONN_CTX_META_KEY); if (connCtx != null) connCtx.onDisconnected(); if (log.isDebugEnabled()) { if (e == null) log.debug("Client disconnected: " + ses.remoteAddress()); else log.debug("Client disconnected due to an error [addr=" + ses.remoteAddress() + ", err=" + e + ']'); } }
/** {@inheritDoc} */ @Override public void dropAllConnections() { Collection<? extends GridNioSession> sessions = srv.sessions(); for (GridNioSession ses : sessions) { ClientListenerConnectionContext connCtx = ses.meta(CONN_CTX_META_KEY); if (connCtx == null || ses.closeTime() != 0) continue; // Skip non-initialized or closed session. srv.close(ses); log.info("Client session has been dropped: " + clientConnectionDescription(ses, connCtx)); } }