![]() |
![]() |
selenium-server-standalone-2.42.2: org.jboss.netty.channel.socket.oio.OioClientSocketPipelineSink.1 * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.io.PushbackInputStream; import java.net.Socket; import java.net.SocketAddress; import java.util.concurrent.Executor; import org.jboss.netty.channel.ChannelEvent; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelFutureListener; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelState; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.socket.SocketChannelConfig; import org.jboss.netty.util.ThreadRenamingRunnable; import org.jboss.netty.util.internal.DeadLockProofWorker; class OioClientSocketPipelineSink extends AbstractOioChannelSink { private final Executor workerExecutor; OioClientSocketPipelineSink(Executor workerExecutor) { this.workerExecutor = workerExecutor; } public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) throws Exception { OioClientSocketChannel channel = (OioClientSocketChannel)e.getChannel(); ChannelFuture future = e.getFuture(); if ((e instanceof ChannelStateEvent)) { ChannelStateEvent stateEvent = (ChannelStateEvent)e; ChannelState state = stateEvent.getState(); Object value = stateEvent.getValue(); switch (state) { case OPEN: if (Boolean.FALSE.equals(value)) { AbstractOioWorker.close(channel, future); } break; case BOUND: if (value != null) { bind(channel, future, (SocketAddress)value); } else { AbstractOioWorker.close(channel, future); } break; case CONNECTED: if (value != null) { connect(channel, future, (SocketAddress)value); } else { AbstractOioWorker.close(channel, future); } break; case INTEREST_OPS: AbstractOioWorker.setInterestOps(channel, future, ((Integer)value).intValue()); } } else if ((e instanceof MessageEvent)) { OioWorker.write(channel, future, ((MessageEvent)e).getMessage()); } } private static void bind(OioClientSocketChannel channel, ChannelFuture future, SocketAddress localAddress) { try { socket.bind(localAddress); future.setSuccess(); Channels.fireChannelBound(channel, channel.getLocalAddress()); } catch (Throwable t) { future.setFailure(t); Channels.fireExceptionCaught(channel, t); } } private void connect(OioClientSocketChannel channel, ChannelFuture future, SocketAddress remoteAddress) { boolean bound = channel.isBound(); boolean connected = false; boolean workerStarted = false; future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE); try { socket.connect(remoteAddress, channel.getConfig().getConnectTimeoutMillis()); connected = true; in = new PushbackInputStream(socket.getInputStream(), 1); out = socket.getOutputStream(); future.setSuccess(); if (!bound) { Channels.fireChannelBound(channel, channel.getLocalAddress()); } Channels.fireChannelConnected(channel, channel.getRemoteAddress()); DeadLockProofWorker.start(workerExecutor, new ThreadRenamingRunnable(new OioWorker(channel), "Old I/O client worker (" + channel + ')')); workerStarted = true; } catch (Throwable t) { future.setFailure(t); Channels.fireExceptionCaught(channel, t); } finally { if ((connected) && (!workerStarted)) { AbstractOioWorker.close(channel, future); } } } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioClientSocketPipelineSink * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.MulticastSocket; import java.net.NetworkInterface; import java.net.SocketException; import org.jboss.netty.channel.ChannelException; import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelSink; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.socket.DatagramChannel; import org.jboss.netty.channel.socket.DatagramChannelConfig; import org.jboss.netty.channel.socket.DefaultDatagramChannelConfig; final class OioDatagramChannel extends AbstractOioChannel implements DatagramChannel { final MulticastSocket socket; private final DatagramChannelConfig config; OioDatagramChannel(ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) { super(null, factory, pipeline, sink); try { socket = new MulticastSocket(null); } catch (IOException e) { throw new ChannelException("Failed to open a datagram socket.", e); } try { socket.setSoTimeout(10); socket.setBroadcast(false); } catch (SocketException e) { throw new ChannelException("Failed to configure the datagram socket timeout.", e); } config = new DefaultDatagramChannelConfig(socket); Channels.fireChannelOpen(this); } public DatagramChannelConfig getConfig() { return config; } public ChannelFuture joinGroup(InetAddress multicastAddress) { ensureBound(); try { socket.joinGroup(multicastAddress); return Channels.succeededFuture(this); } catch (IOException e) { return Channels.failedFuture(this, e); } } public ChannelFuture joinGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface) { ensureBound(); try { socket.joinGroup(multicastAddress, networkInterface); return Channels.succeededFuture(this); } catch (IOException e) { return Channels.failedFuture(this, e); } } private void ensureBound() { if (!isBound()) { throw new IllegalStateException(DatagramChannel.class.getName() + " must be bound to join a group."); } } public ChannelFuture leaveGroup(InetAddress multicastAddress) { try { socket.leaveGroup(multicastAddress); return Channels.succeededFuture(this); } catch (IOException e) { return Channels.failedFuture(this, e); } } public ChannelFuture leaveGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface) { try { socket.leaveGroup(multicastAddress, networkInterface); return Channels.succeededFuture(this); } catch (IOException e) { return Channels.failedFuture(this, e); } } boolean isSocketBound() { return socket.isBound(); } boolean isSocketConnected() { return socket.isConnected(); } InetSocketAddress getLocalSocketAddress() throws Exception { return (InetSocketAddress)socket.getLocalSocketAddress(); } InetSocketAddress getRemoteSocketAddress() throws Exception { return (InetSocketAddress)socket.getRemoteSocketAddress(); } void closeSocket() throws IOException { socket.close(); } boolean isSocketClosed() { return socket.isClosed(); } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioDatagramChannel * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.socket.DatagramChannel; import org.jboss.netty.channel.socket.DatagramChannelFactory; import org.jboss.netty.util.internal.ExecutorUtil; public class OioDatagramChannelFactory implements DatagramChannelFactory { private final Executor workerExecutor; final OioDatagramPipelineSink sink; public OioDatagramChannelFactory() { this(Executors.newCachedThreadPool()); } public OioDatagramChannelFactory(Executor workerExecutor) { if (workerExecutor == null) { throw new NullPointerException("workerExecutor"); } this.workerExecutor = workerExecutor; sink = new OioDatagramPipelineSink(workerExecutor); } public DatagramChannel newChannel(ChannelPipeline pipeline) { return new OioDatagramChannel(this, pipeline, sink); } public void releaseExternalResources() { ExecutorUtil.terminate(new Executor[] { workerExecutor }); } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; class OioDatagramPipelineSink$1 {} /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioDatagramPipelineSink.1 * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.net.MulticastSocket; import java.net.SocketAddress; import java.util.concurrent.Executor; import org.jboss.netty.channel.ChannelEvent; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelFutureListener; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelState; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.util.ThreadRenamingRunnable; import org.jboss.netty.util.internal.DeadLockProofWorker; class OioDatagramPipelineSink extends AbstractOioChannelSink { private final Executor workerExecutor; OioDatagramPipelineSink(Executor workerExecutor) { this.workerExecutor = workerExecutor; } public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) throws Exception { OioDatagramChannel channel = (OioDatagramChannel)e.getChannel(); ChannelFuture future = e.getFuture(); if ((e instanceof ChannelStateEvent)) { ChannelStateEvent stateEvent = (ChannelStateEvent)e; ChannelState state = stateEvent.getState(); Object value = stateEvent.getValue(); switch (state) { case OPEN: if (Boolean.FALSE.equals(value)) { AbstractOioWorker.close(channel, future); } break; case BOUND: if (value != null) { bind(channel, future, (SocketAddress)value); } else { AbstractOioWorker.close(channel, future); } break; case CONNECTED: if (value != null) { connect(channel, future, (SocketAddress)value); } else { OioDatagramWorker.disconnect(channel, future); } break; case INTEREST_OPS: AbstractOioWorker.setInterestOps(channel, future, ((Integer)value).intValue()); } } else if ((e instanceof MessageEvent)) { MessageEvent evt = (MessageEvent)e; OioDatagramWorker.write(channel, future, evt.getMessage(), evt.getRemoteAddress()); } } private void bind(OioDatagramChannel channel, ChannelFuture future, SocketAddress localAddress) { boolean bound = false; boolean workerStarted = false; try { socket.bind(localAddress); bound = true; future.setSuccess(); Channels.fireChannelBound(channel, channel.getLocalAddress()); DeadLockProofWorker.start(workerExecutor, new ThreadRenamingRunnable(new OioDatagramWorker(channel), "Old I/O datagram worker (" + channel + ')')); workerStarted = true; } catch (Throwable t) { future.setFailure(t); Channels.fireExceptionCaught(channel, t); } finally { if ((bound) && (!workerStarted)) { AbstractOioWorker.close(channel, future); } } } private void connect(OioDatagramChannel channel, ChannelFuture future, SocketAddress remoteAddress) { boolean bound = channel.isBound(); boolean connected = false; boolean workerStarted = false; future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE); remoteAddress = null; try { socket.connect(remoteAddress); connected = true; future.setSuccess(); if (!bound) { Channels.fireChannelBound(channel, channel.getLocalAddress()); } Channels.fireChannelConnected(channel, channel.getRemoteAddress()); String threadName = "Old I/O datagram worker (" + channel + ')'; if (!bound) { DeadLockProofWorker.start(workerExecutor, new ThreadRenamingRunnable(new OioDatagramWorker(channel), threadName)); } else { Thread workerThread = workerThread; if (workerThread != null) { try { workerThread.setName(threadName); } catch (SecurityException e) {} } } workerStarted = true; } catch (Throwable t) { future.setFailure(t); Channels.fireExceptionCaught(channel, t); } finally { if ((connected) && (!workerStarted)) { AbstractOioWorker.close(channel, future); } } } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioDatagramPipelineSink * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.io.IOException; import java.io.InterruptedIOException; import java.net.DatagramPacket; import java.net.MulticastSocket; import java.net.SocketAddress; import java.nio.ByteBuffer; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBufferFactory; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.ReceiveBufferSizePredictor; import org.jboss.netty.channel.socket.DatagramChannelConfig; class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> { OioDatagramWorker(OioDatagramChannel channel) { super(channel); } boolean process() throws IOException { ReceiveBufferSizePredictor predictor = ((OioDatagramChannel)channel).getConfig().getReceiveBufferSizePredictor(); byte[] buf = new byte[predictor.nextReceiveBufferSize()]; DatagramPacket packet = new DatagramPacket(buf, buf.length); try { channel).socket.receive(packet); } catch (InterruptedIOException e) { return true; } Channels.fireMessageReceived(channel, ((OioDatagramChannel)channel).getConfig().getBufferFactory().getBuffer(buf, 0, packet.getLength()), packet.getSocketAddress()); return true; } static void write(OioDatagramChannel channel, ChannelFuture future, Object message, SocketAddress remoteAddress) { boolean iothread = isIoThread(channel); try { ChannelBuffer buf = (ChannelBuffer)message; int offset = buf.readerIndex(); int length = buf.readableBytes(); ByteBuffer nioBuf = buf.toByteBuffer(); DatagramPacket packet; DatagramPacket packet; if (nioBuf.hasArray()) { packet = new DatagramPacket(nioBuf.array(), nioBuf.arrayOffset() + offset, length); } else { byte[] arrayBuf = new byte[length]; buf.getBytes(0, arrayBuf); packet = new DatagramPacket(arrayBuf, length); } if (remoteAddress != null) { packet.setSocketAddress(remoteAddress); } socket.send(packet); if (iothread) { Channels.fireWriteComplete(channel, length); } else { Channels.fireWriteCompleteLater(channel, length); } future.setSuccess(); } catch (Throwable t) { future.setFailure(t); if (iothread) { Channels.fireExceptionCaught(channel, t); } else { Channels.fireExceptionCaughtLater(channel, t); } } } static void disconnect(OioDatagramChannel channel, ChannelFuture future) { boolean connected = channel.isConnected(); boolean iothread = isIoThread(channel); try { socket.disconnect(); future.setSuccess(); if (connected) { if (iothread) { Channels.fireChannelDisconnected(channel); } else { Channels.fireChannelDisconnectedLater(channel); } } } catch (Throwable t) { future.setFailure(t); if (iothread) { Channels.fireExceptionCaught(channel, t); } else { Channels.fireExceptionCaughtLater(channel, t); } } } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioDatagramWorker * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.io.IOException; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.jboss.netty.channel.AbstractServerChannel; import org.jboss.netty.channel.ChannelException; import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelSink; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.socket.DefaultServerSocketChannelConfig; import org.jboss.netty.channel.socket.ServerSocketChannel; import org.jboss.netty.channel.socket.ServerSocketChannelConfig; import org.jboss.netty.logging.InternalLogger; import org.jboss.netty.logging.InternalLoggerFactory; class OioServerSocketChannel extends AbstractServerChannel implements ServerSocketChannel { private static final InternalLogger logger = InternalLoggerFactory.getInstance(OioServerSocketChannel.class); final ServerSocket socket; final Lock shutdownLock = new ReentrantLock(); private final ServerSocketChannelConfig config; OioServerSocketChannel(ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) { super(factory, pipeline, sink); try { socket = new ServerSocket(); } catch (IOException e) { throw new ChannelException("Failed to open a server socket.", e); } try { socket.setSoTimeout(1000); } catch (IOException e) { try { socket.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn("Failed to close a partially initialized socket.", e2); } } throw new ChannelException("Failed to set the server socket timeout.", e); } config = new DefaultServerSocketChannelConfig(socket); Channels.fireChannelOpen(this); } public ServerSocketChannelConfig getConfig() { return config; } public InetSocketAddress getLocalAddress() { return (InetSocketAddress)socket.getLocalSocketAddress(); } public InetSocketAddress getRemoteAddress() { return null; } public boolean isBound() { return (isOpen()) && (socket.isBound()); } protected boolean setClosed() { return super.setClosed(); } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioServerSocketChannel * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelSink; import org.jboss.netty.channel.socket.ServerSocketChannel; import org.jboss.netty.channel.socket.ServerSocketChannelFactory; import org.jboss.netty.util.internal.ExecutorUtil; public class OioServerSocketChannelFactory implements ServerSocketChannelFactory { final Executor bossExecutor; private final Executor workerExecutor; private final ChannelSink sink; public OioServerSocketChannelFactory() { this(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); } public OioServerSocketChannelFactory(Executor bossExecutor, Executor workerExecutor) { if (bossExecutor == null) { throw new NullPointerException("bossExecutor"); } if (workerExecutor == null) { throw new NullPointerException("workerExecutor"); } this.bossExecutor = bossExecutor; this.workerExecutor = workerExecutor; sink = new OioServerSocketPipelineSink(workerExecutor); } public ServerSocketChannel newChannel(ChannelPipeline pipeline) { return new OioServerSocketChannel(this, pipeline, sink); } public void releaseExternalResources() { ExecutorUtil.terminate(new Executor[] { bossExecutor, workerExecutor }); } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; class OioServerSocketPipelineSink$1 {} /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioServerSocketPipelineSink.1 * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketTimeoutException; import java.util.concurrent.locks.Lock; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.socket.ServerSocketChannelConfig; import org.jboss.netty.logging.InternalLogger; import org.jboss.netty.util.ThreadRenamingRunnable; import org.jboss.netty.util.internal.DeadLockProofWorker; final class OioServerSocketPipelineSink$Boss implements Runnable { private final OioServerSocketChannel channel; OioServerSocketPipelineSink$Boss(OioServerSocketPipelineSink paramOioServerSocketPipelineSink, OioServerSocketChannel channel) { this.channel = channel; } public void run() { channel.shutdownLock.lock(); try { for (;;) { if (channel.isBound()) { try { Socket acceptedSocket = channel.socket.accept(); try { ChannelPipeline pipeline = channel.getConfig().getPipelineFactory().getPipeline(); OioAcceptedSocketChannel acceptedChannel = new OioAcceptedSocketChannel(channel, channel.getFactory(), pipeline, this$0, acceptedSocket); DeadLockProofWorker.start(this$0.workerExecutor, new ThreadRenamingRunnable(new OioWorker(acceptedChannel), "Old I/O server worker (parentId: " + channel.getId() + ", " + channel + ')')); } catch (Exception e) { if (OioServerSocketPipelineSink.logger.isWarnEnabled()) { OioServerSocketPipelineSink.logger.warn("Failed to initialize an accepted socket.", e); } try { acceptedSocket.close(); } catch (IOException e2) { if (OioServerSocketPipelineSink.logger.isWarnEnabled()) { OioServerSocketPipelineSink.logger.warn("Failed to close a partially accepted socket.", e2); } } } } catch (SocketTimeoutException e) {}catch (Throwable e) { if ((!channel.socket.isBound()) || (!channel.socket.isClosed())) { if (OioServerSocketPipelineSink.logger.isWarnEnabled()) { OioServerSocketPipelineSink.logger.warn("Failed to accept a connection.", e); } try { Thread.sleep(1000L); } catch (InterruptedException e1) {} } } } } } finally { channel.shutdownLock.unlock(); } } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioServerSocketPipelineSink.Boss * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; import java.net.SocketTimeoutException; import java.util.concurrent.Executor; import java.util.concurrent.locks.Lock; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelEvent; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.ChannelState; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.socket.ServerSocketChannelConfig; import org.jboss.netty.logging.InternalLogger; import org.jboss.netty.logging.InternalLoggerFactory; import org.jboss.netty.util.ThreadRenamingRunnable; import org.jboss.netty.util.internal.DeadLockProofWorker; class OioServerSocketPipelineSink extends AbstractOioChannelSink { static final InternalLogger logger = InternalLoggerFactory.getInstance(OioServerSocketPipelineSink.class); final Executor workerExecutor; OioServerSocketPipelineSink(Executor workerExecutor) { this.workerExecutor = workerExecutor; } public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) throws Exception { Channel channel = e.getChannel(); if ((channel instanceof OioServerSocketChannel)) { handleServerSocket(e); } else if ((channel instanceof OioAcceptedSocketChannel)) { handleAcceptedSocket(e); } } private void handleServerSocket(ChannelEvent e) { if (!(e instanceof ChannelStateEvent)) { return; } ChannelStateEvent event = (ChannelStateEvent)e; OioServerSocketChannel channel = (OioServerSocketChannel)event.getChannel(); ChannelFuture future = event.getFuture(); ChannelState state = event.getState(); Object value = event.getValue(); switch (state) { case OPEN: if (Boolean.FALSE.equals(value)) { close(channel, future); } break; case BOUND: if (value != null) { bind(channel, future, (SocketAddress)value); } else { close(channel, future); } break; } } private static void handleAcceptedSocket(ChannelEvent e) { if ((e instanceof ChannelStateEvent)) { ChannelStateEvent event = (ChannelStateEvent)e; OioAcceptedSocketChannel channel = (OioAcceptedSocketChannel)event.getChannel(); ChannelFuture future = event.getFuture(); ChannelState state = event.getState(); Object value = event.getValue(); switch (state) { case OPEN: if (Boolean.FALSE.equals(value)) { AbstractOioWorker.close(channel, future); } break; case BOUND: case CONNECTED: if (value == null) { AbstractOioWorker.close(channel, future); } break; case INTEREST_OPS: AbstractOioWorker.setInterestOps(channel, future, ((Integer)value).intValue()); } } else if ((e instanceof MessageEvent)) { MessageEvent event = (MessageEvent)e; OioSocketChannel channel = (OioSocketChannel)event.getChannel(); ChannelFuture future = event.getFuture(); Object message = event.getMessage(); OioWorker.write(channel, future, message); } } private void bind(OioServerSocketChannel channel, ChannelFuture future, SocketAddress localAddress) { boolean bound = false; boolean bossStarted = false; try { socket.bind(localAddress, channel.getConfig().getBacklog()); bound = true; future.setSuccess(); localAddress = channel.getLocalAddress(); Channels.fireChannelBound(channel, localAddress); Executor bossExecutor = getFactorybossExecutor; DeadLockProofWorker.start(bossExecutor, new ThreadRenamingRunnable(new Boss(channel), "Old I/O server boss (" + channel + ')')); bossStarted = true; } catch (Throwable t) { future.setFailure(t); Channels.fireExceptionCaught(channel, t); } finally { if ((!bossStarted) && (bound)) { close(channel, future); } } } private static void close(OioServerSocketChannel channel, ChannelFuture future) { boolean bound = channel.isBound(); try { socket.close(); shutdownLock.lock(); try { if (channel.setClosed()) { future.setSuccess(); if (bound) { Channels.fireChannelUnbound(channel); } Channels.fireChannelClosed(channel); } else { future.setSuccess(); } } finally { shutdownLock.unlock(); } } catch (Throwable t) { future.setFailure(t); Channels.fireExceptionCaught(channel, t); } } private final class Boss implements Runnable { private final OioServerSocketChannel channel; Boss(OioServerSocketChannel channel) { this.channel = channel; } public void run() { channel.shutdownLock.lock(); try { for (;;) { if (channel.isBound()) { try { Socket acceptedSocket = channel.socket.accept(); try { ChannelPipeline pipeline = channel.getConfig().getPipelineFactory().getPipeline(); OioAcceptedSocketChannel acceptedChannel = new OioAcceptedSocketChannel(channel, channel.getFactory(), pipeline, OioServerSocketPipelineSink.this, acceptedSocket); DeadLockProofWorker.start(workerExecutor, new ThreadRenamingRunnable(new OioWorker(acceptedChannel), "Old I/O server worker (parentId: " + channel.getId() + ", " + channel + ')')); } catch (Exception e) { if (OioServerSocketPipelineSink.logger.isWarnEnabled()) { OioServerSocketPipelineSink.logger.warn("Failed to initialize an accepted socket.", e); } try { acceptedSocket.close(); } catch (IOException e2) { if (OioServerSocketPipelineSink.logger.isWarnEnabled()) { OioServerSocketPipelineSink.logger.warn("Failed to close a partially accepted socket.", e2); } } } } catch (SocketTimeoutException e) {}catch (Throwable e) { if ((!channel.socket.isBound()) || (!channel.socket.isClosed())) { if (OioServerSocketPipelineSink.logger.isWarnEnabled()) { OioServerSocketPipelineSink.logger.warn("Failed to accept a connection.", e); } try { Thread.sleep(1000L); } catch (InterruptedException e1) {} } } } } } finally { channel.shutdownLock.unlock(); } } } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioServerSocketPipelineSink * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.io.IOException; import java.io.OutputStream; import java.io.PushbackInputStream; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelException; import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelSink; import org.jboss.netty.channel.socket.DefaultSocketChannelConfig; import org.jboss.netty.channel.socket.SocketChannel; import org.jboss.netty.channel.socket.SocketChannelConfig; abstract class OioSocketChannel extends AbstractOioChannel implements SocketChannel { final Socket socket; private final SocketChannelConfig config; OioSocketChannel(Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, Socket socket) { super(parent, factory, pipeline, sink); this.socket = socket; try { socket.setSoTimeout(1000); } catch (SocketException e) { throw new ChannelException("Failed to configure the OioSocketChannel socket timeout.", e); } config = new DefaultSocketChannelConfig(socket); } public SocketChannelConfig getConfig() { return config; } abstract PushbackInputStream getInputStream(); abstract OutputStream getOutputStream(); boolean isSocketBound() { return socket.isBound(); } boolean isSocketConnected() { return socket.isConnected(); } InetSocketAddress getLocalSocketAddress() throws Exception { return (InetSocketAddress)socket.getLocalSocketAddress(); } InetSocketAddress getRemoteSocketAddress() throws Exception { return (InetSocketAddress)socket.getRemoteSocketAddress(); } void closeSocket() throws IOException { socket.close(); } boolean isSocketClosed() { return socket.isClosed(); } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioSocketChannel * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.channel.socket.oio; import java.io.IOException; import java.io.OutputStream; import java.io.PushbackInputStream; import java.net.SocketException; import java.nio.channels.ClosedChannelException; import java.nio.channels.WritableByteChannel; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBufferFactory; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.DefaultFileRegion; import org.jboss.netty.channel.FileRegion; import org.jboss.netty.channel.socket.SocketChannelConfig; class OioWorker extends AbstractOioWorker<OioSocketChannel> { private static final Pattern SOCKET_CLOSED_MESSAGE = Pattern.compile("^.*(?:Socket.*closed).*$", 2); OioWorker(OioSocketChannel channel) { super(channel); } public void run() { boolean fireConnected = channel instanceof OioAcceptedSocketChannel; if ((fireConnected) && (((OioSocketChannel)channel).isOpen())) { org.jboss.netty.channel.Channels.fireChannelConnected(channel, ((OioSocketChannel)channel).getRemoteAddress()); } super.run(); } boolean process() throws IOException { PushbackInputStream in = ((OioSocketChannel)channel).getInputStream(); int bytesToRead = in.available(); int readBytes; if (bytesToRead > 0) { byte[] buf = new byte[bytesToRead]; readBytes = in.read(buf); } else { int b = in.read(); if (b < 0) { return false; } in.unread(b); return true; } int readBytes; byte[] buf; org.jboss.netty.channel.Channels.fireMessageReceived(channel, ((OioSocketChannel)channel).getConfig().getBufferFactory().getBuffer(buf, 0, readBytes)); return true; } static void write(OioSocketChannel channel, ChannelFuture future, Object message) { boolean iothread = isIoThread(channel); OutputStream out = channel.getOutputStream(); if (out == null) { Exception e = new ClosedChannelException(); future.setFailure(e); if (iothread) { org.jboss.netty.channel.Channels.fireExceptionCaught(channel, e); } else { org.jboss.netty.channel.Channels.fireExceptionCaughtLater(channel, e); } return; } try { int length = 0; if ((message instanceof FileRegion)) { FileRegion fr = (FileRegion)message; try { synchronized (out) { WritableByteChannel bchannel = java.nio.channels.Channels.newChannel(out); long i = 0L; while ((i = fr.transferTo(bchannel, length)) > 0L) { length = (int)(length + i); if (length >= fr.getCount()) { break; } } } } finally { if ((fr instanceof DefaultFileRegion)) { DefaultFileRegion dfr = (DefaultFileRegion)fr; if (dfr.releaseAfterTransfer()) { fr.releaseExternalResources(); } } } } else { ChannelBuffer a = (ChannelBuffer)message; length = a.readableBytes(); synchronized (out) { a.getBytes(a.readerIndex(), out, length); } } future.setSuccess(); if (iothread) { org.jboss.netty.channel.Channels.fireWriteComplete(channel, length); } else { org.jboss.netty.channel.Channels.fireWriteCompleteLater(channel, length); } } catch (Throwable t) { if (((t instanceof SocketException)) && (SOCKET_CLOSED_MESSAGE.matcher(String.valueOf(t.getMessage())).matches())) { t = new ClosedChannelException(); } future.setFailure(t); if (iothread) { org.jboss.netty.channel.Channels.fireExceptionCaught(channel, t); } else { org.jboss.netty.channel.Channels.fireExceptionCaughtLater(channel, t); } } } } /* Location: * Qualified Name: org.jboss.netty.channel.socket.oio.OioWorker * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.container.microcontainer; import org.jboss.netty.logging.InternalLoggerFactory; import org.jboss.netty.logging.JBossLoggerFactory; public class NettyLoggerConfigurator { public NettyLoggerConfigurator() { InternalLoggerFactory.setDefaultFactory(new JBossLoggerFactory()); } } /* Location: * Qualified Name: org.jboss.netty.container.microcontainer.NettyLoggerConfigurator * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.container.osgi; import org.jboss.netty.logging.InternalLoggerFactory; import org.jboss.netty.logging.OsgiLoggerFactory; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class NettyBundleActivator implements BundleActivator { private OsgiLoggerFactory loggerFactory; public void start(BundleContext ctx) throws Exception { loggerFactory = new OsgiLoggerFactory(ctx); InternalLoggerFactory.setDefaultFactory(loggerFactory); } public void stop(BundleContext ctx) throws Exception { if (loggerFactory != null) { InternalLoggerFactory.setDefaultFactory(loggerFactory.getFallback()); loggerFactory.destroy(); loggerFactory = null; } } } /* Location: * Qualified Name: org.jboss.netty.container.osgi.NettyBundleActivator * Java Class Version: 5 (49.0) * JD-Core Version: 0.7.1 */ package org.jboss.netty.container.spring; import org.jboss.netty.logging.CommonsLoggerFactory; import org.jboss.netty.logging.InternalLoggerFactory; public class NettyLoggerConfigurator { public NettyLoggerConfigurator() { InternalLoggerFactory.setDefaultFactory(new CommonsLoggerFactory()); } } /* Location: * Qualified Name: org.jboss.netty.container.spring.NettyLoggerConfigurator * Java Class Version: 5 (49.0) * JD-Core Version: Further reading...For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.New!JAR listings
|