Bug 1029: Remove dead code: sal-schema-repository-api
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / handler / ssh / virtualsocket / ChannelOutputStream.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.netconf.util.handler.ssh.virtualsocket;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import io.netty.channel.ChannelHandlerContext;
14 import io.netty.channel.ChannelOutboundHandler;
15 import io.netty.channel.ChannelPromise;
16
17 import java.io.OutputStream;
18 import java.net.SocketAddress;
19
20 /**
21  * Class provides {@link OutputStream) functionality to users of virtual socket.
22  */
23 public class ChannelOutputStream extends OutputStream implements ChannelOutboundHandler {
24     private final Object lock = new Object();
25     private ByteBuf buff = Unpooled.buffer();
26     private ChannelHandlerContext ctx;
27
28     @Override
29     public void flush() {
30         synchronized(lock) {
31             ctx.writeAndFlush(buff).awaitUninterruptibly();
32             buff = Unpooled.buffer();
33         }
34     }
35
36     @Override
37     public void write(int b) {
38         synchronized(lock) {
39             buff.writeByte(b);
40         }
41     }
42
43     public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
44                      ChannelPromise promise) {
45         ctx.bind(localAddress, promise);
46     }
47
48     public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
49                         SocketAddress localAddress, ChannelPromise promise) {
50         this.ctx = ctx;
51         ctx.connect(remoteAddress, localAddress, promise);
52     }
53
54     public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) {
55         ctx.disconnect(promise);
56     }
57
58     public void close(ChannelHandlerContext ctx, ChannelPromise promise) {
59         ctx.close(promise);
60     }
61
62     public void deregister(ChannelHandlerContext ctx, ChannelPromise channelPromise) {
63         ctx.deregister(channelPromise);
64     }
65
66     public void read(ChannelHandlerContext ctx) {
67         ctx.read();
68     }
69
70     public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
71         // pass
72     }
73
74     public void flush(ChannelHandlerContext ctx) {
75         // pass
76     }
77
78     public void handlerAdded(ChannelHandlerContext ctx)
79             throws Exception {
80     }
81
82     public void handlerRemoved(ChannelHandlerContext ctx)
83             throws Exception {
84     }
85
86     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
87         ctx.fireExceptionCaught(cause);
88     }
89 }