• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SocketChannel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jboss.netty.channel.socket.SocketChannel的典型用法代码示例。如果您正苦于以下问题:Java SocketChannel类的具体用法?Java SocketChannel怎么用?Java SocketChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SocketChannel类属于org.jboss.netty.channel.socket包,在下文中一共展示了SocketChannel类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: newChannel

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:TestAvroSource.java


示例2: run

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
/**
 * 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);
			}
		}
		
	}
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:24,代码来源:ControllerConnector.java


示例3: getShuffle

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
@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();
    }
  };
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:13,代码来源:TestShuffleHandler.java


示例4: setupChannel

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
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);
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:38,代码来源:ProxyTest.java


示例5: newChannel

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
    try {
        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
        sslContext.init(null, new TrustManager[]{new BogusTrustManager(publicKey)},
                null);
        SSLEngine sslEngine = sslContext.createSSLEngine();
        sslEngine.setUseClientMode(true);
        pipeline.addFirst("ssl", new SslHandler(sslEngine));
        return super.newChannel(pipeline);
    } catch (Exception ex) {
        throw new RuntimeException("Cannot create SSL channel", ex);
    }
}
 
开发者ID:ChristopherMann,项目名称:2FactorWallet,代码行数:15,代码来源:TLSClientHelper.java


示例6: createClientChannel

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
private SocketChannel createClientChannel() {
	InetSocketAddress serverAddress = new InetSocketAddress("localhost",
			SERVER_PORT);
	ChannelFuture clientChannelFuture = clientBootstrap
			.connect(serverAddress);
	try {
		if (!clientChannelFuture.await(1000, TimeUnit.MILLISECONDS)) {
			LOG.severe("did not connect within acceptable time period");
			return null;
		}
	} catch (InterruptedException e) {
		LOG.severe("Interrupted while waiting for client connect to be established");
		return null;
	}

	if (!clientChannelFuture.isSuccess()) {
		LOG.log(Level.SEVERE, "did not connect successfully",
				clientChannelFuture.getCause());
		return null;
	}

	HttpTunnelClientChannelConfig config = (HttpTunnelClientChannelConfig) clientChannelFuture
			.getChannel().getConfig();
	config.setWriteBufferHighWaterMark(2 * 1024 * 1024);
	config.setWriteBufferLowWaterMark(1024 * 1024);

	return (SocketChannel) clientChannelFuture.getChannel();
}
 
开发者ID:reines,项目名称:httptunnel,代码行数:29,代码来源:HttpTunnelSoakTester.java


示例7: newChannel

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
	FakeSocketChannel channel = new FakeSocketChannel(null, this, pipeline,
			new FakeChannelSink());
	createdChannels.add(channel);
	return channel;
}
 
开发者ID:reines,项目名称:httptunnel,代码行数:8,代码来源:FakeClientSocketChannelFactory.java


示例8: newChannel

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
@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);
      List<String> enabledProtocols = new ArrayList<String>();
      for (String protocol : sslEngine.getEnabledProtocols()) {
        if (!excludeProtocols.contains(protocol)) {
          enabledProtocols.add(protocol);
        }
      }
      sslEngine.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
      logger.info("SSLEngine protocols enabled: " +
          Arrays.asList(sslEngine.getEnabledProtocols()));
      // 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);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:59,代码来源:NettyAvroRpcClient.java


示例9: newChannel

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
public SocketChannel newChannel(ChannelPipeline pipeline) {
    return new NioClientSocketChannel(this, pipeline, sink, workerPool.nextWorker());
}
 
开发者ID:nyankosama,项目名称:simple-netty-source,代码行数:4,代码来源:NioClientSocketChannelFactory.java


示例10: newChannel

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
public SocketChannel newChannel(ChannelPipeline pipeline) {
	return new NioClientSocketChannel(this, pipeline, sink, workerPool.nextWorker());
}
 
开发者ID:urunimi,项目名称:android-netty,代码行数:4,代码来源:NioClientSocketChannelFactory.java


示例11: run

import org.jboss.netty.channel.socket.SocketChannel; //导入依赖的package包/类
public void run() throws InterruptedException {
	LOG.info("binding server channel");
	Channel serverChannel = serverBootstrap.bind(new InetSocketAddress(
			SERVER_PORT));
	channels.add(serverChannel);
	LOG.log(Level.INFO, "server channel bound to {0}",
			serverChannel.getLocalAddress());

	SocketChannel clientChannel = createClientChannel();
	if (clientChannel == null) {
		LOG.severe("no client channel - bailing out");
		return;
	}

	channels.add(clientChannel);
	c2sDataSender.setChannel(clientChannel);

	executor.execute(c2sDataSender);

	if (!c2sDataSender.waitForFinish(5, TimeUnit.MINUTES)) {
		LOG.severe("Data send from client to server failed");
	}

	if (!s2cDataSender.waitForFinish(5, TimeUnit.MINUTES)) {
		LOG.severe("Data send from server to client failed");
	}

	LOG.log(Level.INFO, "Waiting for verification to complete");
	if (!c2sVerifier.waitForCompletion(30L, TimeUnit.SECONDS)) {
		LOG.warning("Timed out waiting for verification of client-to-server stream");
	}

	if (!s2cVerifier.waitForCompletion(30L, TimeUnit.SECONDS)) {
		LOG.warning("Timed out waiting for verification of server-to-client stream");
	}

	LOG.info("closing client channel");
	closeChannel(clientChannel);
	LOG.info("server channel status: "
			+ (serverChannel.isOpen() ? "open" : "closed"));
	LOG.info("closing server channel");
	closeChannel(serverChannel);
}
 
开发者ID:reines,项目名称:httptunnel,代码行数:44,代码来源:HttpTunnelSoakTester.java



注:本文中的org.jboss.netty.channel.socket.SocketChannel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BlockSignPost类代码示例发布时间:2022-05-22
下一篇:
Java Content类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap