private RequestDispatcher getRequestDispatcher() { return getChannel().getPipeline().get(RequestDispatcher.class); }
private RequestDispatcher getRequestDispatcher() { return getChannel().getPipeline().get(RequestDispatcher.class); }
/** * Creates a new instance of {@link CoapClient}. * * @param name the name of the application (used for logging purposes) * @param clientSocket the socket to send {@link CoapMessage}s */ public CoapClient(String name, InetSocketAddress clientSocket) { super(name); ClientChannelPipelineFactory factory = new ClientChannelPipelineFactory(this.getExecutor()); startApplication(factory, clientSocket); this.responseDispatcher = getChannel().getPipeline().get(ResponseDispatcher.class); }
/** * Creates a new instance of {@link CoapEndpoint} * * @param applicationName the name of this {@link CoapEndpoint} (for logging only) * @param notFoundHandler the {@link NotFoundHandler} to handle inbound requests for unknown resources * @param localSocket the socket address to send and receive messages */ public CoapEndpoint(String applicationName, NotFoundHandler notFoundHandler, InetSocketAddress localSocket, BlockSize maxBlock1Size, BlockSize maxBlock2Size) { super(applicationName); CoapEndpointChannelPipelineFactory pipelineFactory = new CoapEndpointChannelPipelineFactory( this.getExecutor(), new TokenFactory(), notFoundHandler, maxBlock1Size, maxBlock2Size ); startApplication(pipelineFactory, localSocket); // retrieve the request dispatcher (server component) this.requestDispatcher = getChannel().getPipeline().get(RequestDispatcher.class); // register .well-known/core this.requestDispatcher.registerWellKnownCoreResource(); // retrieve the response dispatcher (client component) this.responseDispatcher = getChannel().getPipeline().get(ResponseDispatcher.class); }
/** * <p>Creates a new instance of {@link CoapServer}</p> * * @param name the name of this {@link CoapServer} (for logging only) * @param notFoundHandler the {@link NotFoundHandler} to handle inbound requests for unknown resources * @param serverSocket the socket address for the server to listen at * @param maxBlock1Size the maximum blocksize for inbound requests * @param maxBlock2Size the maximum blocksize for outbound responses */ public CoapServer(String name, NotFoundHandler notFoundHandler, InetSocketAddress serverSocket, BlockSize maxBlock1Size, BlockSize maxBlock2Size) { super(name); CoapServerChannelPipelineFactory pipelineFactory = new CoapServerChannelPipelineFactory(this.getExecutor(), notFoundHandler, maxBlock1Size, maxBlock2Size); startApplication(pipelineFactory, serverSocket); // set the request dispatcher and register .well-known/core this.requestDispatcher = getChannel().getPipeline().get(RequestDispatcher.class); this.requestDispatcher.registerWellKnownCoreResource(); }
/** * Starts this application * * @param pipelineFactory the {@link CoapChannelPipelineFactory} that creates the instances of * {@link AbstractCoapChannelHandler}s that deal with inbound and outbound messages * @param localSocket the socket address to be used for inbound and outbound messages */ protected void startApplication(CoapChannelPipelineFactory pipelineFactory, InetSocketAddress localSocket) { //ChannelFactory channelFactory = new NioDatagramChannelFactory(executor, executor.getCorePoolSize() / 2 ); ChannelFactory channelFactory = new NioDatagramChannelFactory(executor, 1 ); //System.out.println("Threads: " + (executor.getCorePoolSize() - 1)); //Create and configure bootstrap ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(channelFactory); bootstrap.setPipelineFactory(pipelineFactory); bootstrap.setOption("receiveBufferSizePredictor", new FixedReceiveBufferSizePredictor(RECEIVE_BUFFER_SIZE)); //Create datagram channel this.channel = (DatagramChannel) bootstrap.bind(localSocket); // set the channel handler contexts for (ChannelHandler handler : pipelineFactory.getChannelHandlers()) { if (handler instanceof AbstractCoapChannelHandler) { ChannelHandlerContext context = this.channel.getPipeline().getContext(handler.getClass()); ((AbstractCoapChannelHandler) handler).setContext(context); } } }