Merge "BUG-1568 Remove unused VirtualSocket"
authorTony Tkacik <ttkacik@cisco.com>
Tue, 26 Aug 2014 07:37:31 +0000 (07:37 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 26 Aug 2014 07:37:31 +0000 (07:37 +0000)
opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/ChannelInputStream.java [deleted file]
opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/ChannelOutputStream.java [deleted file]
opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/VirtualSocket.java [deleted file]

diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/ChannelInputStream.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/ChannelInputStream.java
deleted file mode 100644 (file)
index ba65b9e..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandler;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Class provides {@link InputStream} functionality to users of virtual socket.
- */
-public class ChannelInputStream extends InputStream implements ChannelInboundHandler {
-    private final Object lock = new Object();
-    private final ByteBuf bb = Unpooled.buffer();
-
-    @Override
-    public int read(byte b[], int off, int len) throws IOException {
-        if (b == null) {
-            throw new NullPointerException();
-        } else if (off < 0 || len < 0 || len > b.length - off) {
-            throw new IndexOutOfBoundsException();
-        } else if (len == 0) {
-            return 0;
-        }
-
-        int bytesRead = 1;
-        synchronized (lock) {
-            int c = read();
-
-            b[off] = (byte)c;
-
-            if(this.bb.readableBytes() == 0) {
-                return bytesRead;
-            }
-
-            int ltr = len-1;
-            ltr = (ltr <= bb.readableBytes()) ? ltr : bb.readableBytes();
-
-            bb.readBytes(b, 1, ltr);
-            bytesRead += ltr;
-        }
-        return bytesRead;
-    }
-
-    @Override
-    public int read() throws IOException {
-        synchronized (lock) {
-            while (this.bb.readableBytes() == 0) {
-                try {
-                    lock.wait();
-                } catch (InterruptedException e) {
-                    Thread.currentThread().interrupt();
-                    throw new IllegalStateException(e);
-                }
-            }
-            return this.bb.readByte() & 0xFF;
-        }
-    }
-
-    @Override
-    public int available() throws IOException {
-        synchronized (lock) {
-            return this.bb.readableBytes();
-        }
-    }
-
-    public void channelRegistered(ChannelHandlerContext ctx) {
-        ctx.fireChannelRegistered();
-    }
-
-    public void channelUnregistered(ChannelHandlerContext ctx) {
-        ctx.fireChannelUnregistered();
-    }
-
-    public void channelActive(ChannelHandlerContext ctx) {
-        ctx.fireChannelActive();
-    }
-
-    public void channelInactive(ChannelHandlerContext ctx) {
-        ctx.fireChannelInactive();
-    }
-
-    public void channelRead(ChannelHandlerContext ctx, Object o) {
-        synchronized(lock) {
-            this.bb.discardReadBytes();
-            this.bb.writeBytes((ByteBuf) o);
-            ((ByteBuf) o).release();
-            lock.notifyAll();
-        }
-    }
-
-    public void channelReadComplete(ChannelHandlerContext ctx) {
-        ctx.fireChannelReadComplete();
-    }
-
-    public void userEventTriggered(ChannelHandlerContext ctx, Object o) {
-        ctx.fireUserEventTriggered(o);
-    }
-
-    public void channelWritabilityChanged(ChannelHandlerContext ctx) {
-        ctx.fireChannelWritabilityChanged();
-    }
-
-    public void handlerAdded(ChannelHandlerContext ctx) {
-    }
-
-    public void handlerRemoved(ChannelHandlerContext ctx) {
-    }
-
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable throwable) {
-        ctx.fireExceptionCaught(throwable);
-    }
-}
-
diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/ChannelOutputStream.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/ChannelOutputStream.java
deleted file mode 100644 (file)
index 2dc5235..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelOutboundHandler;
-import io.netty.channel.ChannelPromise;
-
-import java.io.OutputStream;
-import java.net.SocketAddress;
-
-/**
- * Class provides {@link OutputStream) functionality to users of virtual socket.
- */
-public class ChannelOutputStream extends OutputStream implements ChannelOutboundHandler {
-    private final Object lock = new Object();
-    private ByteBuf buff = Unpooled.buffer();
-    private ChannelHandlerContext ctx;
-
-    @Override
-    public void flush() {
-        synchronized(lock) {
-            ctx.writeAndFlush(buff).awaitUninterruptibly();
-            buff = Unpooled.buffer();
-        }
-    }
-
-    @Override
-    public void write(int b) {
-        synchronized(lock) {
-            buff.writeByte(b);
-        }
-    }
-
-    public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
-                     ChannelPromise promise) {
-        ctx.bind(localAddress, promise);
-    }
-
-    public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
-                        SocketAddress localAddress, ChannelPromise promise) {
-        this.ctx = ctx;
-        ctx.connect(remoteAddress, localAddress, promise);
-    }
-
-    public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) {
-        ctx.disconnect(promise);
-    }
-
-    public void close(ChannelHandlerContext ctx, ChannelPromise promise) {
-        ctx.close(promise);
-    }
-
-    public void deregister(ChannelHandlerContext ctx, ChannelPromise channelPromise) {
-        ctx.deregister(channelPromise);
-    }
-
-    public void read(ChannelHandlerContext ctx) {
-        ctx.read();
-    }
-
-    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
-        // pass
-    }
-
-    public void flush(ChannelHandlerContext ctx) {
-        // pass
-    }
-
-    public void handlerAdded(ChannelHandlerContext ctx)
-            throws Exception {
-    }
-
-    public void handlerRemoved(ChannelHandlerContext ctx)
-            throws Exception {
-    }
-
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
-        ctx.fireExceptionCaught(cause);
-    }
-}
diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/VirtualSocket.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/virtualsocket/VirtualSocket.java
deleted file mode 100644 (file)
index 69cce80..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.nio.channels.SocketChannel;
-
-/**
- * Handler class providing Socket functionality to OIO client application. By using VirtualSocket user can
- * use OIO application in asynchronous environment and NIO EventLoop. Using VirtualSocket OIO applications
- * are able to use full potential of NIO environment.
- */
-//TODO: refactor - socket should be created when connection is established
-public class VirtualSocket extends Socket implements ChannelHandler {
-    private static final String INPUT_STREAM = "inputStream";
-    private static final String OUTPUT_STREAM = "outputStream";
-
-    private final ChannelInputStream chais = new ChannelInputStream();
-    private final ChannelOutputStream chaos = new ChannelOutputStream();
-    private ChannelHandlerContext ctx;
-
-
-    public InputStream getInputStream() {
-        return this.chais;
-    }
-
-    public OutputStream getOutputStream() {
-        return this.chaos;
-    }
-
-    public void handlerAdded(ChannelHandlerContext ctx) {
-        this.ctx = ctx;
-
-        if (ctx.channel().pipeline().get(OUTPUT_STREAM) == null) {
-            ctx.channel().pipeline().addFirst(OUTPUT_STREAM, chaos);
-        }
-
-        if (ctx.channel().pipeline().get(INPUT_STREAM) == null) {
-            ctx.channel().pipeline().addFirst(INPUT_STREAM, chais);
-        }
-    }
-
-    public void handlerRemoved(ChannelHandlerContext ctx) {
-        if (ctx.channel().pipeline().get(OUTPUT_STREAM) != null) {
-            ctx.channel().pipeline().remove(OUTPUT_STREAM);
-        }
-
-        if (ctx.channel().pipeline().get(INPUT_STREAM) != null) {
-            ctx.channel().pipeline().remove(INPUT_STREAM);
-        }
-    }
-
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable throwable) {
-        // TODO exceptionCaught is deprecated transform this handler
-        ctx.fireExceptionCaught(throwable);
-    }
-
-
-    @Override
-    public void connect(SocketAddress endpoint) throws IOException {}
-
-    @Override
-    public void connect(SocketAddress endpoint, int timeout) throws IOException {}
-
-    @Override
-    public void bind(SocketAddress bindpoint) throws IOException {}
-
-    @Override
-    public InetAddress getInetAddress() {
-        InetSocketAddress isa = getInetSocketAddress();
-        return isa.getAddress();
-    }
-
-    @Override
-    public InetAddress getLocalAddress() {return null;}
-
-    @Override
-    public int getPort() {
-        return getInetSocketAddress().getPort();
-    }
-
-    private InetSocketAddress getInetSocketAddress() {
-        return (InetSocketAddress)getRemoteSocketAddress();
-    }
-
-    @Override
-    public int getLocalPort() {return -1;}
-
-    @Override
-    public SocketAddress getRemoteSocketAddress() {
-        return this.ctx.channel().remoteAddress();
-    }
-
-    @Override
-    public SocketAddress getLocalSocketAddress() {
-        return this.ctx.channel().localAddress();
-    }
-
-    @Override
-    public SocketChannel getChannel() {return null;}
-
-    @Override
-    public void setTcpNoDelay(boolean on) throws SocketException {}
-
-    @Override
-    public boolean getTcpNoDelay() throws SocketException {return false;}
-
-    @Override
-    public void setSoLinger(boolean on, int linger) throws SocketException {}
-
-    @Override
-    public int getSoLinger() throws SocketException {return -1;}
-
-    @Override
-    public void sendUrgentData(int data) throws IOException {}
-
-    @Override
-    public void setOOBInline(boolean on) throws SocketException {}
-
-    @Override
-    public boolean getOOBInline() throws SocketException {return false;}
-
-    @Override
-    public synchronized void setSoTimeout(int timeout) throws SocketException {}
-
-    @Override
-    public synchronized int getSoTimeout() throws SocketException {return -1;}
-
-    @Override
-    public synchronized void setSendBufferSize(int size) throws SocketException {}
-
-    @Override
-    public synchronized int getSendBufferSize() throws SocketException {return -1;}
-
-    @Override
-    public synchronized void setReceiveBufferSize(int size) throws SocketException {}
-
-    @Override
-    public synchronized int getReceiveBufferSize() throws SocketException {return -1;}
-
-    @Override
-    public void setKeepAlive(boolean on) throws SocketException {}
-
-    @Override
-    public boolean getKeepAlive() throws SocketException {return false;}
-
-    @Override
-    public void setTrafficClass(int tc) throws SocketException {}
-
-    @Override
-    public int getTrafficClass() throws SocketException {return -1;}
-
-    @Override
-    public void setReuseAddress(boolean on) throws SocketException {}
-
-    @Override
-    public boolean getReuseAddress() throws SocketException {return false;}
-
-    @Override
-    public synchronized void close() throws IOException {}
-
-    @Override
-    public void shutdownInput() throws IOException {}
-
-    @Override
-    public void shutdownOutput() throws IOException {}
-
-    @Override
-    public String toString() {
-        return "VirtualSocket{" + getInetAddress() + ":" + getPort() + "}";
-    }
-
-    @Override
-    public boolean isConnected() {return false;}
-
-    @Override
-    public boolean isBound() {return false;}
-
-    @Override
-    public boolean isClosed() {return false;}
-
-    @Override
-    public boolean isInputShutdown() {return false;}
-
-    @Override
-    public boolean isOutputShutdown() {return false;}
-
-    @Override
-    public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {}
-}