/** * Construct a server. * * @param builder builder with configuration for server * @param transportServer transport server that will create new incoming transports * @param rootContext context that callbacks for new RPCs should be derived from */ ServerImpl( AbstractServerImplBuilder<?> builder, InternalServer transportServer, Context rootContext) { this.executorPool = Preconditions.checkNotNull(builder.executorPool, "executorPool"); this.registry = Preconditions.checkNotNull(builder.registryBuilder.build(), "registryBuilder"); this.fallbackRegistry = Preconditions.checkNotNull(builder.fallbackRegistry, "fallbackRegistry"); this.transportServer = Preconditions.checkNotNull(transportServer, "transportServer"); // Fork from the passed in context so that it does not propagate cancellation, it only // inherits values. this.rootContext = Preconditions.checkNotNull(rootContext, "rootContext").fork(); this.decompressorRegistry = builder.decompressorRegistry; this.compressorRegistry = builder.compressorRegistry; this.transportFilters = Collections.unmodifiableList( new ArrayList<ServerTransportFilter>(builder.transportFilters)); this.interceptors = builder.interceptors.toArray(new ServerInterceptor[builder.interceptors.size()]); this.handshakeTimeoutMillis = builder.handshakeTimeoutMillis; }
@Override public Attributes transportReady(Attributes attributes) { handshakeTimeoutFuture.cancel(false); handshakeTimeoutFuture = null; for (ServerTransportFilter filter : transportFilters) { attributes = Preconditions.checkNotNull(filter.transportReady(attributes), "Filter %s returned null", filter); } this.attributes = attributes; return attributes; }
@Override public void transportTerminated() { if (handshakeTimeoutFuture != null) { handshakeTimeoutFuture.cancel(false); handshakeTimeoutFuture = null; } for (ServerTransportFilter filter : transportFilters) { filter.transportTerminated(attributes); } transportClosed(transport); }
@Override public DropwizardServerBuilder addTransportFilter(final ServerTransportFilter filter) { origin.addTransportFilter(filter); return this; }
@Override public final T addTransportFilter(ServerTransportFilter filter) { transportFilters.add(checkNotNull(filter, "filter")); return thisT(); }