org.jboss.netty.channel.socket.SocketChannel Java Examples

The following examples show how to use org.jboss.netty.channel.socket.SocketChannel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAvroSource.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
  try {
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, new TrustManager[]{new PermissiveTrustManager()},
                    null);
    SSLEngine sslEngine = sslContext.createSSLEngine();
    sslEngine.setUseClientMode(true);
    // addFirst() will make SSL handling the first stage of decoding
    // and the last stage of encoding
    pipeline.addFirst("ssl", new SslHandler(sslEngine));
    return super.newChannel(pipeline);
  } catch (Exception ex) {
    throw new RuntimeException("Cannot create SSL channel", ex);
  }
}
 
Example #2
Source File: ControllerConnector.java    From FlowSpaceFirewall with Apache License 2.0 6 votes vote down vote up
/**
 * everytime the timer fires run this!
 * Looks through every proxy and determines if the proxy needs to 
 * attempt to connect to the controller.
 */
public synchronized void run(){
	log.debug("Looking for controllers not currently connected");
	Iterator <Long> it = proxies.keySet().iterator();
	while(it.hasNext()){
		List <Proxy> ps = proxies.get(it.next());
		Iterator <Proxy> proxyIt = ps.iterator();
		while(proxyIt.hasNext()){
			Proxy p = proxyIt.next();
			log.debug("Proxy for " + p.getSwitch().getStringId() + " " + p.getSlicer().getControllerAddress().toString() + " is connected: " + p.connected());
			if(!p.connected() && p.getAdminStatus()){
				log.debug("Creating new Channel to " + p.getSlicer().getControllerAddress().toString() + " for switch: " + p.getSwitch().getStringId());
				SocketChannel controller_channel = channelCreator.newChannel(getPipeline());
				p.connect(controller_channel);
			}
		}
		
	}
}
 
Example #3
Source File: TestAvroSource.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
  try {

    ZlibEncoder encoder = new ZlibEncoder(compressionLevel);
    pipeline.addFirst("deflater", encoder);
    pipeline.addFirst("inflater", new ZlibDecoder());
    return super.newChannel(pipeline);
  } catch (Exception ex) {
    throw new RuntimeException("Cannot create Compression channel", ex);
  }
}
 
Example #4
Source File: ProxyTest.java    From FlowSpaceFirewall with Apache License 2.0 5 votes vote down vote up
public void setupChannel() throws IOException{
	ChannelFuture future = createMock(org.jboss.netty.channel.ChannelFuture.class);
	ChannelPipeline pipeline = createMock(org.jboss.netty.channel.ChannelPipeline.class);
	ChannelHandlerContext context = createMock(org.jboss.netty.channel.ChannelHandlerContext.class);
	handler = EasyMock.createNiceMock(edu.iu.grnoc.flowspace_firewall.OFControllerChannelHandler.class);
	channel = EasyMock.createNiceMock(org.jboss.netty.channel.socket.SocketChannel.class);
	
	ChannelFuture otherFuture = createMock(org.jboss.netty.channel.ChannelFuture.class);
	expect(channel.getPipeline()).andReturn(pipeline).anyTimes();
	expect(pipeline.getContext("handler")).andReturn(context).anyTimes();
	expect(context.getHandler()).andReturn(handler).anyTimes();
	expect(channel.connect(EasyMock.isA(java.net.InetSocketAddress.class))).andReturn(future).anyTimes();
	expect(channel.write(EasyMock.isA(org.openflow.protocol.OFMessage.class))).andReturn(otherFuture).anyTimes();
	
	handler.setSwitch(EasyMock.isA(net.floodlightcontroller.core.IOFSwitch.class));
	EasyMock.expectLastCall().anyTimes();
	
	handler.setProxy(EasyMock.isA(edu.iu.grnoc.flowspace_firewall.Proxy.class));
	EasyMock.expectLastCall().anyTimes();
	
	handler.sendMessage(EasyMock.isA(org.openflow.protocol.OFMessage.class));
	EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
	    public Object answer() {
	        //supply your mock implementation here...
	        messagesSentToController.add((OFMessage)EasyMock.getCurrentArguments()[0]);
	        //return the value to be returned by the method (null for void)
	        return null;
	    }
	}).anyTimes();
	
	
	EasyMock.replay(future);
	EasyMock.replay(pipeline);
	EasyMock.replay(context);
	//EasyMock.replay(handler);
	EasyMock.replay(otherFuture);
}
 
Example #5
Source File: TestShuffleHandler.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
protected Shuffle getShuffle(final Configuration conf) {
  return new Shuffle(conf) {
    @Override
    protected void verifyRequest(String appid, ChannelHandlerContext ctx,
        HttpRequest request, HttpResponse response, URL requestUri)
        throws IOException {
      SocketChannel channel = (SocketChannel)(ctx.getChannel());
      socketKeepAlive = channel.getConfig().isKeepAlive();
    }
  };
}
 
Example #6
Source File: NioClientSocketChannelFactory.java    From simple-netty-source with Apache License 2.0 4 votes vote down vote up
public SocketChannel newChannel(ChannelPipeline pipeline) {
    return new NioClientSocketChannel(this, pipeline, sink, workerPool.nextWorker());
}
 
Example #7
Source File: NettyAvroRpcClient.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
  TrustManager[] managers;
  try {
    if (enableCompression) {
      ZlibEncoder encoder = new ZlibEncoder(compressionLevel);
      pipeline.addFirst("deflater", encoder);
      pipeline.addFirst("inflater", new ZlibDecoder());
    }
    if (enableSsl) {
      if (trustAllCerts) {
        logger.warn("No truststore configured, setting TrustManager to accept"
            + " all server certificates");
        managers = new TrustManager[] { new PermissiveTrustManager() };
      } else {
        KeyStore keystore = null;

        if (truststore != null) {
          if (truststorePassword == null) {
            throw new NullPointerException("truststore password is null");
          }
          InputStream truststoreStream = new FileInputStream(truststore);
          keystore = KeyStore.getInstance(truststoreType);
          keystore.load(truststoreStream, truststorePassword.toCharArray());
        }

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        // null keystore is OK, with SunX509 it defaults to system CA Certs
        // see http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#X509TrustManager
        tmf.init(keystore);
        managers = tmf.getTrustManagers();
      }

      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(null, managers, null);
      SSLEngine sslEngine = sslContext.createSSLEngine();
      sslEngine.setUseClientMode(true);
      // addFirst() will make SSL handling the first stage of decoding
      // and the last stage of encoding this must be added after
      // adding compression handling above
      pipeline.addFirst("ssl", new SslHandler(sslEngine));
    }

    return super.newChannel(pipeline);
  } catch (Exception ex) {
    logger.error("Cannot create SSL channel", ex);
    throw new RuntimeException("Cannot create SSL channel", ex);
  }
}
 
Example #8
Source File: NioClientSocketChannelFactory.java    From android-netty with Apache License 2.0 4 votes vote down vote up
public SocketChannel newChannel(ChannelPipeline pipeline) {
	return new NioClientSocketChannel(this, pipeline, sink, workerPool.nextWorker());
}