/** * Reconstructs object on demarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of demarshalling error. */ private Object readResolve() throws ObjectStreamException { GridTuple2<GridCacheContext, String> t = stash.get(); try { return t.get1().dataStructures().sequence(t.get2(), 0L, false, false); } catch (GridException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); } }
/** * Tries to start server with given parameters. * * @param hostAddr Host on which server should be bound. * @param port Port on which server should be bound. * @param lsnr Server message listener. * @param parser Server message parser. * @param sslCtx SSL context in case if SSL is enabled. * @param cfg Configuration for other parameters. * @return {@code True} if server successfully started, {@code false} if port is used and server * was unable to start. */ private boolean startTcpServer( InetAddress hostAddr, int port, GridNioServerListener<GridClientMessage> lsnr, GridNioParser parser, @Nullable SSLContext sslCtx, GridConfiguration cfg) { try { GridNioFilter codec = new GridNioCodecFilter(parser, log, false); GridNioFilter[] filters; if (sslCtx != null) { GridNioSslFilter sslFilter = new GridNioSslFilter(sslCtx, log); boolean auth = cfg.isRestTcpSslClientAuth(); sslFilter.wantClientAuth(auth); sslFilter.needClientAuth(auth); filters = new GridNioFilter[] {codec, sslFilter}; } else filters = new GridNioFilter[] {codec}; srv = GridNioServer.<GridClientMessage>builder() .address(hostAddr) .port(port) .listener(lsnr) .logger(log) .selectorCount(cfg.getRestTcpSelectorCount()) .gridName(ctx.gridName()) .tcpNoDelay(cfg.isRestTcpNoDelay()) .directBuffer(cfg.isRestTcpDirectBuffer()) .byteOrder(ByteOrder.nativeOrder()) .socketSendBufferSize(cfg.getRestTcpSendBufferSize()) .socketReceiveBufferSize(cfg.getRestTcpReceiveBufferSize()) .sendQueueLimit(cfg.getRestTcpSendQueueLimit()) .filters(filters) .build(); srv.idleTimeout(cfg.getRestIdleTimeout()); srv.start(); ctx.ports().registerPort(port, GridPortProtocol.TCP, getClass()); return true; } catch (GridException e) { if (log.isDebugEnabled()) log.debug( "Failed to start " + name() + " protocol on port " + port + ": " + e.getMessage()); return false; } }
/** * Reconstructs object on demarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of demarshalling error. */ @SuppressWarnings({"ConstantConditions"}) private Object readResolve() throws ObjectStreamException { GridTuple2<GridCacheContext, String> t = stash.get(); try { return t.get1().dataStructures().countDownLatch(t.get2(), 0, false, false); } catch (GridException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); } }
/** * Checks entry for empty value. * * @param entry Entry to check. * @return {@code True} if entry is empty. */ private boolean empty(GridCacheEntry<K, V> entry) { try { return entry.peek(F.asList(GLOBAL)) == null; } catch (GridException e) { U.error(null, e.getMessage(), e); assert false : "Should never happen: " + e; return false; } }
/** * Checks that the given grid configuration will lead to {@link GridException} upon grid startup. * * @param cfg Grid configuration to check. * @param excMsgSnippet Root cause (assertion) exception message snippet. * @param testLoc {@code True} if checking is done for "testLocal" tests. */ private void checkGridStartFails( GridConfiguration cfg, CharSequence excMsgSnippet, boolean testLoc) { assertNotNull(cfg); assertNotNull(excMsgSnippet); try { G.start(cfg); fail("No exception has been thrown."); } catch (GridException e) { if (testLoc) { if ("Failed to start processor: GridProcessorAdapter []".equals(e.getMessage()) && e.getCause().getMessage().contains(excMsgSnippet)) return; // Expected exception. } else if (e.getMessage().contains(excMsgSnippet)) return; // Expected exception. error("Caught unexpected exception.", e); fail(); } }
/** * Reconstructs object on demarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of demarshalling error. */ @SuppressWarnings("unchecked") private Object readResolve() throws ObjectStreamException { try { GridBiTuple<GridCacheContext, String> t = stash.get(); return t.get1().dataStructures().atomicReference(t.get2(), null, false); } catch (GridException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); } finally { stash.remove(); } }