Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright (c) xsocket.org, 2006 - 2008. All rights reserved.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
   *  License as published by the Free Software Foundation; either
   *  version 2.1 of the License, or (at your option) any later version.
   *
   *  This library is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  *  Lesser General Public License for more details.
  *
  *  You should have received a copy of the GNU Lesser General Public
  *  License along with this library; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
  * The latest copy of this software may be found on http://www.xsocket.org/
  */
 package org.xsocket.connection.multiplexed;
 
 
 
 
 
A helper class to register IPipelineHandler on the org.xsocket.connection.Server
   ...
   IServer server = new Server(new MultiplexedProtocolAdapter(new MyHandler()));
   server.start();
   ...

   
   class MyHandler implements IPipelineDataHandler {

      public boolean onData(INonBlockingPipeline pipeline) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
          byte[] data = pipeline.readBytesByDelimiter(DELIMITER);
          pipeline.write(data);
          pipeline.write(DELIMITER);
          pipeline.flush();
          
          return true;
      }
   }

 

Author(s):
grro
 
 public final class MultiplexedProtocolAdapter implements IConnectHandlerILifeCycleMBeanRegistration {
 	
 	
 	
 	private IServer server = null;
 
 	private IHandler handler = null;
 	private IMultiplexer multiplexer = null;

constructor

Parameters:
handler the handler (supported: IPipelineConnectHandler, IPipelineDisconnectHandler, IPipelineDataHandler, IPipelineIdleTimeoutHandler, IPipelineConnectionTimeoutHandlerIConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)
 
 	public MultiplexedProtocolAdapter(IHandler handler) {
 		this(handlernew SimpleMultiplexer());
 	}

  

constructor

Parameters:
handler the handler (supported: IPipelineConnectHandler, IPipelineDisconnectHandler, IPipelineDataHandler, IPipelineIdleTimeoutHandler, IPipelineConnectionTimeoutHandlerIConnectHandler, IDisconnectHandler, IDataHandler, IIdleTimeoutHandler and IConnectionTimeoutHandler)
multiplexer the multiplexer
	public MultiplexedProtocolAdapter(IHandler handlerIMultiplexer multiplexer) {
		this. = handler;
		this. = multiplexer;
	}


	public void onInit() {
		.setStartUpLogMessage(.getStartUpLogMessage() + "; multiplexed " + MultiplexedUtils.getImplementationVersion());
		 = PipelineHandlerAdapter.newInstance();
	}


	public void onDestroy() {
	}


	public ObjectName preRegister(MBeanServer serverObjectName namethrows Exception {
		return MultiplexedUtils.exportMbean(servername);
	}

	public void postRegister(Boolean registrationDone) {
	}

	public void postDeregister() {
	}

	public void preDeregister() throws Exception {
	}


	public boolean onConnect(INonBlockingConnection connectionthrows IOException {
		// the multiplexed connection replaces the current handler by a own one
		return true;
	}	
New to GrepCode? Check out our FAQ X