You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by dr...@apache.org on 2015/06/11 16:37:49 UTC
[2/3] directory-kerby git commit: Remove kerby-event and event model
network support for now as its not mature yet
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/Connector.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/Connector.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/Connector.java
deleted file mode 100644
index 720f481..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/Connector.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport;
-
-import java.net.InetSocketAddress;
-
-public abstract class Connector extends TransportSelector {
-
- public Connector(TransportHandler transportHandler) {
- super(transportHandler);
- }
-
- public void connect(String serverAddress, int serverPort) {
- InetSocketAddress sa = new InetSocketAddress(serverAddress, serverPort);
- doConnect(sa);
- }
-
- protected abstract void doConnect(InetSocketAddress sa);
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/MessageHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/MessageHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/MessageHandler.java
deleted file mode 100644
index d6ad01e..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/MessageHandler.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport;
-
-import org.apache.kerby.event.AbstractEventHandler;
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.transport.event.MessageEvent;
-import org.apache.kerby.transport.event.TransportEventType;
-
-public abstract class MessageHandler extends AbstractEventHandler {
-
- @Override
- protected void doHandle(Event event) throws Exception {
- handleMessage((MessageEvent) event);
- }
-
- protected abstract void handleMessage(MessageEvent event) throws Exception;
-
- @Override
- public EventType[] getInterestedEvents() {
- return new EventType[] { TransportEventType.INBOUND_MESSAGE };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/Network.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/Network.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/Network.java
deleted file mode 100644
index 9ade687..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/Network.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport;
-
-import org.apache.kerby.event.AbstractEventHandler;
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.event.LongRunningEventHandler;
-import org.apache.kerby.transport.event.AddressEvent;
-import org.apache.kerby.transport.event.TransportEvent;
-import org.apache.kerby.transport.tcp.*;
-import org.apache.kerby.transport.udp.UdpAddressEvent;
-import org.apache.kerby.transport.udp.UdpEventType;
-import org.apache.kerby.transport.udp.UdpTransport;
-import org.apache.kerby.transport.udp.UdpTransportHandler;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.nio.channels.*;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A combined and mixed network facility handling UDP and TCP in both connect and accept sides
- */
-public class Network extends LongRunningEventHandler {
-
- private Selector selector;
- private StreamingDecoder streamingDecoder;
- private UdpTransportHandler udpTransportHandler;
- private TcpTransportHandler tcpTransportHandler;
-
- class MyEventHandler extends AbstractEventHandler {
- @Override
- protected void doHandle(Event event) throws Exception {
- if (event.getEventType() == UdpEventType.ADDRESS_CONNECT) {
- doUdpConnect((AddressEvent) event);
- } else if (event.getEventType() == UdpEventType.ADDRESS_BIND) {
- doUdpBind((AddressEvent) event);
- } else if (event.getEventType() == TcpEventType.ADDRESS_CONNECT) {
- doTcpConnect((AddressEvent) event);
- } else if (event.getEventType() == TcpEventType.ADDRESS_BIND) {
- doTcpBind((AddressEvent) event);
- }
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return new EventType[]{
- UdpEventType.ADDRESS_CONNECT,
- UdpEventType.ADDRESS_BIND,
- TcpEventType.ADDRESS_CONNECT,
- TcpEventType.ADDRESS_BIND
- };
- }
- }
-
- public Network() {
- setEventHandler(new MyEventHandler());
- }
-
- @Override
- public void init() {
- super.init();
-
- try {
- selector = Selector.open();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * TCP transport only, for decoding tcp streaming into messages
- * @param streamingDecoder
- */
- public void setStreamingDecoder(StreamingDecoder streamingDecoder) {
- this.streamingDecoder = streamingDecoder;
- }
-
- /**
- * TCP only. Connect on the given server address. Can be called multiple times
- * for multiple servers
- * @param serverAddress
- * @param serverPort
- */
- public void tcpConnect(String serverAddress, int serverPort) {
- InetSocketAddress sa = new InetSocketAddress(serverAddress, serverPort);
- checkTcpTransportHandler();
- doTcpConnect(sa);
- }
-
- /**
- * UDP only. Connect on the given server address. Can be called multiple times
- * for multiple servers
- * @param serverAddress
- * @param serverPort
- */
- public void udpConnect(String serverAddress, int serverPort) {
- InetSocketAddress sa = new InetSocketAddress(serverAddress, serverPort);
- checkUdpTransportHandler();
- doUdpConnect(sa);
- }
-
- /**
- * TCP only. Listen and accept connections on the address. Can be called multiple
- * times for multiple server addresses.
- * @param serverAddress
- * @param serverPort
- */
- public void tcpListen(String serverAddress, int serverPort) {
- InetSocketAddress sa = new InetSocketAddress(serverAddress, serverPort);
- checkTcpTransportHandler();
- doTcpListen(sa);
- }
-
- /**
- * UDP only. Listen and accept connections on the address. Can be called multiple
- * times for multiple server addresses.
- * @param serverAddress
- * @param serverPort
- */
- public void udpListen(String serverAddress, int serverPort) {
- InetSocketAddress sa = new InetSocketAddress(serverAddress, serverPort);
- checkUdpTransportHandler();
- doUdpListen(sa);
- }
-
- @Override
- protected void loopOnce() {
- try {
- selectOnce();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void selectOnce() throws IOException {
- if (selector.isOpen() && selector.select(2) > 0 && selector.isOpen()) {
- Set<SelectionKey> selectionKeys = selector.selectedKeys();
- Iterator<SelectionKey> iterator = selectionKeys.iterator();
- while (iterator.hasNext()) {
- SelectionKey selectionKey = iterator.next();
- dealKey(selectionKey);
- iterator.remove();
- }
- selectionKeys.clear();
- }
- }
-
- private void checkTcpTransportHandler() {
- if (tcpTransportHandler == null) {
- if (streamingDecoder == null) {
- throw new IllegalArgumentException("No streaming decoder set yet");
- }
- tcpTransportHandler = new TcpTransportHandler(streamingDecoder);
- getDispatcher().register(tcpTransportHandler);
- }
- }
-
- private void checkUdpTransportHandler() {
- if (udpTransportHandler == null) {
- udpTransportHandler = new UdpTransportHandler();
- getDispatcher().register(udpTransportHandler);
- }
- }
-
- private void dealKey(SelectionKey selectionKey) throws IOException {
- if (selectionKey.isConnectable()) {
- doTcpConnect(selectionKey);
- } else if (selectionKey.isAcceptable()) {
- doTcpAccept(selectionKey);
- } else {
- helpHandleSelectionKey(selectionKey);
- }
- }
-
- private void helpHandleSelectionKey(SelectionKey selectionKey) throws IOException {
- SelectableChannel channel = selectionKey.channel();
- if (channel instanceof DatagramChannel) {
- udpTransportHandler.helpHandleSelectionKey(selectionKey);
- } else {
- tcpTransportHandler.helpHandleSelectionKey(selectionKey);
- }
- }
-
- private void doUdpConnect(InetSocketAddress sa) {
- AddressEvent event = UdpAddressEvent.createAddressConnectEvent(sa);
- dispatch(event);
- }
-
- private void doUdpConnect(AddressEvent event) throws IOException {
- InetSocketAddress address = event.getAddress();
- DatagramChannel channel = DatagramChannel.open();
- channel.configureBlocking(false);
- channel.connect(address);
-
- channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
-
- UdpTransport transport = new UdpTransport(channel, address);
- onNewTransport(transport);
- }
-
- protected void doUdpListen(InetSocketAddress socketAddress) {
- AddressEvent event = UdpAddressEvent.createAddressBindEvent(socketAddress);
- dispatch(event);
- }
-
- private void doUdpBind(AddressEvent event) throws IOException {
- DatagramChannel serverChannel = DatagramChannel.open();
- serverChannel.configureBlocking(false);
- serverChannel.bind(event.getAddress());
- serverChannel.register(selector, SelectionKey.OP_READ);
- }
-
- protected void doTcpConnect(InetSocketAddress sa) {
- AddressEvent event = TcpAddressEvent.createAddressConnectEvent(sa);
- dispatch(event);
- }
-
- private void doTcpConnect(AddressEvent event) throws IOException {
- SocketChannel channel = SocketChannel.open();
- channel.configureBlocking(false);
- channel.connect(event.getAddress());
- channel.register(selector,
- SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE);
- }
-
- private void doTcpConnect(SelectionKey key) throws IOException {
- SocketChannel channel = (SocketChannel) key.channel();
- if (channel.isConnectionPending()) {
- channel.finishConnect();
- }
-
- Transport transport = new TcpTransport(channel, tcpTransportHandler.getStreamingDecoder());
- channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE, transport);
- onNewTransport(transport);
- }
-
- protected void doTcpListen(InetSocketAddress socketAddress) {
- AddressEvent event = TcpAddressEvent.createAddressBindEvent(socketAddress);
- dispatch(event);
- }
-
- protected void doTcpAccept(SelectionKey key) throws IOException {
- ServerSocketChannel server = (ServerSocketChannel) key.channel();
- SocketChannel channel;
-
- try {
- while ((channel = server.accept()) != null) {
- channel.configureBlocking(false);
- channel.socket().setTcpNoDelay(true);
- channel.socket().setKeepAlive(true);
-
- Transport transport = new TcpTransport(channel,
- tcpTransportHandler.getStreamingDecoder());
-
- channel.register(selector,
- SelectionKey.OP_READ | SelectionKey.OP_WRITE, transport);
- onNewTransport(transport);
- }
- } catch (ClosedByInterruptException e) { //NOPMD
- // No op as normal
- }
- }
-
- protected void doTcpBind(AddressEvent event) throws IOException {
- ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
- serverSocketChannel.configureBlocking(false);
- ServerSocket serverSocket = serverSocketChannel.socket();
- serverSocket.bind(event.getAddress());
- serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT, serverSocketChannel);
- }
-
- private void onNewTransport(Transport transport) {
- transport.setDispatcher(getDispatcher());
- dispatch(TransportEvent.createNewTransportEvent(transport));
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/Transport.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/Transport.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/Transport.java
deleted file mode 100644
index bdf2ff7..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/Transport.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport;
-
-import org.apache.kerby.event.Dispatcher;
-import org.apache.kerby.transport.buffer.TransBuffer;
-import org.apache.kerby.transport.event.TransportEvent;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-
-public abstract class Transport {
- private InetSocketAddress remoteAddress;
- protected Dispatcher dispatcher;
- private Object attachment;
-
- protected TransBuffer sendBuffer;
-
- protected int readableCount = 0;
- protected int writableCount = 0;
-
- public Transport(InetSocketAddress remoteAddress) {
- this.remoteAddress = remoteAddress;
- this.sendBuffer = new TransBuffer();
- }
-
- public void setDispatcher(Dispatcher dispatcher) {
- this.dispatcher = dispatcher;
- }
-
- public InetSocketAddress getRemoteAddress() {
- return remoteAddress;
- }
-
- public void sendMessage(ByteBuffer message) {
- if (message != null) {
- sendBuffer.write(message);
- dispatcher.dispatch(TransportEvent.createWritableTransportEvent(this));
- }
- }
-
- public void onWriteable() throws IOException {
- this.writableCount ++;
-
- if (! sendBuffer.isEmpty()) {
- ByteBuffer message = sendBuffer.read();
- if (message != null) {
- sendOutMessage(message);
- }
- }
- }
-
- public void onReadable() throws IOException {
- this.readableCount++;
- }
-
- protected abstract void sendOutMessage(ByteBuffer message) throws IOException;
-
- public void setAttachment(Object attachment) {
- this.attachment = attachment;
- }
-
- public Object getAttachment() {
- return attachment;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/TransportHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/TransportHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/TransportHandler.java
deleted file mode 100644
index e745e38..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/TransportHandler.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport;
-
-import org.apache.kerby.event.AbstractEventHandler;
-
-import java.io.IOException;
-import java.nio.channels.SelectionKey;
-
-/**
- * Handling readable and writable events
- */
-public abstract class TransportHandler extends AbstractEventHandler {
-
- public abstract void helpHandleSelectionKey(SelectionKey selectionKey) throws IOException;
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/TransportSelector.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/TransportSelector.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/TransportSelector.java
deleted file mode 100644
index a4016a0..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/TransportSelector.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport;
-
-import org.apache.kerby.event.Dispatcher;
-import org.apache.kerby.event.LongRunningEventHandler;
-import org.apache.kerby.transport.event.TransportEvent;
-
-import java.io.IOException;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.util.Iterator;
-import java.util.Set;
-
-public abstract class TransportSelector extends LongRunningEventHandler {
-
- protected Selector selector;
- protected TransportHandler transportHandler;
-
- public TransportSelector(TransportHandler transportHandler) {
- super();
- this.transportHandler = transportHandler;
- }
-
- @Override
- public void setDispatcher(Dispatcher dispatcher) {
- super.setDispatcher(dispatcher);
- dispatcher.register(transportHandler);
- }
-
- @Override
- public void init() {
- super.init();
-
- try {
- selector = Selector.open();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- protected void loopOnce() {
- try {
- selectOnce();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void selectOnce() throws IOException {
- if (selector.isOpen() && selector.select(10) > 0 && selector.isOpen()) {
- Set<SelectionKey> selectionKeys = selector.selectedKeys();
- Iterator<SelectionKey> iterator = selectionKeys.iterator();
- while (iterator.hasNext()) {
- SelectionKey selectionKey = iterator.next();
- dealKey(selectionKey);
- iterator.remove();
- }
- selectionKeys.clear();
- }
- }
-
- protected void dealKey(SelectionKey selectionKey) throws IOException {
- transportHandler.helpHandleSelectionKey(selectionKey);
- }
-
- protected void onNewTransport(Transport transport) {
- transport.setDispatcher(getDispatcher());
- dispatch(TransportEvent.createNewTransportEvent(transport));
- }
-
- @Override
- public void stop() {
- super.stop();
-
- try {
- selector.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/BufferPool.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/BufferPool.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/BufferPool.java
deleted file mode 100644
index 7737c13..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/BufferPool.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.buffer;
-
-import java.nio.ByteBuffer;
-
-public class BufferPool {
-
- public static ByteBuffer allocate(int len) {
- return ByteBuffer.allocate(len);
- }
-
- public static void release(ByteBuffer buffer) {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/BufferUtil.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/BufferUtil.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/BufferUtil.java
deleted file mode 100644
index f67ab09..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/BufferUtil.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-
-public class BufferUtil {
-
- /**
- * Read len bytes from src buffer
- */
- public static ByteBuffer read(ByteBuffer src, int len) {
- if (len > src.remaining())
- throw new BufferOverflowException();
-
- ByteBuffer result = ByteBuffer.allocate(len);
- int n = src.remaining();
- for (int i = 0; i < n; i++) {
- result.put(src.get());
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/RecvBuffer.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/RecvBuffer.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/RecvBuffer.java
deleted file mode 100644
index 2c190a3..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/RecvBuffer.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-public class RecvBuffer {
-
- private LinkedList<ByteBuffer> bufferQueue;
-
- public RecvBuffer() {
- bufferQueue = new LinkedList<ByteBuffer>();
- }
-
- public synchronized void write(ByteBuffer buffer) {
- bufferQueue.addLast(buffer);
- }
-
- /**
- * Put buffer as the first into the buffer queue
- */
- public synchronized void writeFirst(ByteBuffer buffer) {
- bufferQueue.addFirst(buffer);
- }
-
- /**
- * Read and return the first buffer if available
- */
- public synchronized ByteBuffer readFirst() {
- if (! bufferQueue.isEmpty()) {
- return bufferQueue.removeFirst();
- }
- return null;
- }
-
- /**
- * Read most available bytes into the dst buffer
- */
- public synchronized ByteBuffer readMostBytes() {
- int len = remaining();
- return readBytes(len);
- }
-
- /**
- * Read len bytes into the dst buffer if available
- */
- public synchronized ByteBuffer readBytes(int len) {
- if (remaining() < len) { // no enough data that's available
- throw new BufferOverflowException();
- }
-
- ByteBuffer result = null;
-
- ByteBuffer takenBuffer;
- if (bufferQueue.size() == 1) {
- takenBuffer = bufferQueue.removeFirst();
-
- if (takenBuffer.remaining() == len) {
- return takenBuffer;
- }
-
- result = BufferPool.allocate(len);
- for (int i = 0; i < len; i++) {
- result.put(takenBuffer.get());
- }
- // Has left bytes so put it back for future reading
- if (takenBuffer.remaining() > 0) {
- bufferQueue.addFirst(takenBuffer);
- }
- } else {
- result = BufferPool.allocate(len);
-
- Iterator<ByteBuffer> iter = bufferQueue.iterator();
- int alreadyGot = 0, toGet;
- while (iter.hasNext()) {
- takenBuffer = iter.next();
- iter.remove();
-
- toGet = takenBuffer.remaining() < len - alreadyGot ?
- takenBuffer.remaining() : len -alreadyGot;
- byte[] toGetBytes = new byte[toGet];
- takenBuffer.get(toGetBytes);
- result.put(toGetBytes);
-
- if (takenBuffer.remaining() > 0) {
- bufferQueue.addFirst(takenBuffer);
- }
-
- alreadyGot += toGet;
- if (alreadyGot == len) {
- break;
- }
- }
- }
- result.flip();
-
- return result;
- }
-
- public boolean isEmpty() {
- return bufferQueue.isEmpty();
- }
-
- /**
- * Return count of remaining and left bytes that's available
- */
- public int remaining() {
- if (bufferQueue.isEmpty()) {
- return 0;
- } else if (bufferQueue.size() == 1) {
- return bufferQueue.getFirst().remaining();
- }
-
- int result = 0;
- Iterator<ByteBuffer> iter = bufferQueue.iterator();
- while (iter.hasNext()) {
- result += iter.next().remaining();
- }
- return result;
- }
-
- public synchronized void clear() {
- if (bufferQueue.isEmpty()) {
- return;
- } else if (bufferQueue.size() == 1) {
- BufferPool.release(bufferQueue.getFirst());
- }
-
- Iterator<ByteBuffer> iter = bufferQueue.iterator();
- while (iter.hasNext()) {
- BufferPool.release(iter.next());
- }
- bufferQueue.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/TransBuffer.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/TransBuffer.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/TransBuffer.java
deleted file mode 100644
index 079a6cd..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/buffer/TransBuffer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.buffer;
-
-import java.nio.ByteBuffer;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-
-public class TransBuffer {
-
- private BlockingQueue<ByteBuffer> bufferQueue;
-
- public TransBuffer() {
- bufferQueue = new ArrayBlockingQueue<ByteBuffer>(2);
- }
-
- public void write(ByteBuffer buffer) {
- bufferQueue.add(buffer);
- }
-
- public void write(byte[] buffer) {
- write(ByteBuffer.wrap(buffer));
- }
-
- public ByteBuffer read() {
- return bufferQueue.poll();
- }
-
- public boolean isEmpty() {
- return bufferQueue.isEmpty();
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/AddressEvent.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/AddressEvent.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/AddressEvent.java
deleted file mode 100644
index 80340c8..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/AddressEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.event;
-
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-
-import java.net.InetSocketAddress;
-
-public class AddressEvent extends Event {
-
- private InetSocketAddress address;
-
- public AddressEvent(InetSocketAddress address, EventType eventType) {
- super(eventType);
- this.address = address;
- }
-
- public InetSocketAddress getAddress() {
- return address;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/MessageEvent.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/MessageEvent.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/MessageEvent.java
deleted file mode 100644
index b9d48eb..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/MessageEvent.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.event;
-
-import org.apache.kerby.transport.Transport;
-
-import java.nio.ByteBuffer;
-
-public class MessageEvent extends TransportEvent {
-
- private MessageEvent(Transport transport, ByteBuffer message) {
- super(transport, TransportEventType.INBOUND_MESSAGE, message);
- }
-
- public ByteBuffer getMessage() {
- return (ByteBuffer) getEventData();
- }
-
- public static MessageEvent createInboundMessageEvent(
- Transport transport, ByteBuffer message) {
- return new MessageEvent(transport, message);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/TransportEvent.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/TransportEvent.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/TransportEvent.java
deleted file mode 100644
index 3c2ae34..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/TransportEvent.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.event;
-
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.transport.Transport;
-
-public class TransportEvent extends Event {
-
- private Transport transport;
-
- public TransportEvent(Transport transport, EventType eventType) {
- super(eventType);
- this.transport = transport;
- }
-
- public TransportEvent(Transport transport, EventType eventType, Object eventData) {
- super(eventType, eventData);
- this.transport = transport;
- }
-
- public Transport getTransport() {
- return transport;
- }
-
- public static TransportEvent createWritableTransportEvent(Transport transport) {
- return new TransportEvent(transport, TransportEventType.TRANSPORT_WRITABLE);
- }
-
- public static TransportEvent createReadableTransportEvent(Transport transport) {
- return new TransportEvent(transport, TransportEventType.TRANSPORT_READABLE);
- }
-
- public static TransportEvent createNewTransportEvent(Transport transport) {
- return new TransportEvent(transport, TransportEventType.NEW_TRANSPORT);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/TransportEventType.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/TransportEventType.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/TransportEventType.java
deleted file mode 100644
index 6036c02..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/event/TransportEventType.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.event;
-
-import org.apache.kerby.event.EventType;
-
-public enum TransportEventType implements EventType {
- NEW_TRANSPORT,
- TRANSPORT_WRITABLE,
- TRANSPORT_READABLE,
- INBOUND_MESSAGE
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/DecodingCallback.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/DecodingCallback.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/DecodingCallback.java
deleted file mode 100644
index 561f78f..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/DecodingCallback.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.tcp;
-
-public interface DecodingCallback {
-
- /**
- * OK, enough data is ready, a message can be out
- */
- void onMessageComplete(int messageLength, int adjustOffset);
-
- /**
- * Need more data to be available
- */
- void onMoreDataNeeded();
-
- /**
- * Need more data to be available, with determined more data length given
- */
- void onMoreDataNeeded(int needDataLength);
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/StreamingDecoder.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/StreamingDecoder.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/StreamingDecoder.java
deleted file mode 100644
index 953b34a..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/StreamingDecoder.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.tcp;
-
-import java.nio.ByteBuffer;
-
-public interface StreamingDecoder {
- void decode(ByteBuffer streamingBuffer, DecodingCallback callback);
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpAcceptor.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpAcceptor.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpAcceptor.java
deleted file mode 100644
index 752f5d7..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpAcceptor.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.tcp;
-
-import org.apache.kerby.event.AbstractEventHandler;
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.transport.Acceptor;
-import org.apache.kerby.transport.Transport;
-import org.apache.kerby.transport.event.AddressEvent;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.nio.channels.ClosedByInterruptException;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-
-public class TcpAcceptor extends Acceptor {
-
- public TcpAcceptor(StreamingDecoder streamingDecoder) {
- this(new TcpTransportHandler(streamingDecoder));
- }
-
- public TcpAcceptor(TcpTransportHandler transportHandler) {
- super(transportHandler);
-
- setEventHandler(new AbstractEventHandler() {
- @Override
- protected void doHandle(Event event) throws Exception {
- if (event.getEventType() == TcpEventType.ADDRESS_BIND) {
- try {
- doBind((AddressEvent) event);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return new EventType[] {
- TcpEventType.ADDRESS_BIND
- };
- }
- });
- }
-
- @Override
- protected void doListen(InetSocketAddress socketAddress) {
- AddressEvent event = TcpAddressEvent.createAddressBindEvent(socketAddress);
- dispatch(event);
- }
-
- @Override
- protected void dealKey(SelectionKey selectionKey) throws IOException {
- if (selectionKey.isAcceptable()) {
- doAccept(selectionKey);
- } else {
- super.dealKey(selectionKey);
- }
- }
-
- void doAccept(SelectionKey key) throws IOException {
- ServerSocketChannel server = (ServerSocketChannel) key.channel();
- SocketChannel channel;
-
- try {
- while ((channel = server.accept()) != null) {
- channel.configureBlocking(false);
- channel.socket().setTcpNoDelay(true);
- channel.socket().setKeepAlive(true);
-
- Transport transport = new TcpTransport(channel,
- ((TcpTransportHandler) transportHandler).getStreamingDecoder());
-
- channel.register(selector,
- SelectionKey.OP_READ | SelectionKey.OP_WRITE, transport);
- onNewTransport(transport);
- }
- } catch (ClosedByInterruptException e) { //NOPMD
- // No op as normal
- }
- }
-
- protected void doBind(AddressEvent event) throws IOException {
- ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
- serverSocketChannel.configureBlocking(false);
- ServerSocket serverSocket = serverSocketChannel.socket();
- serverSocket.bind(event.getAddress());
- serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT, serverSocketChannel);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpAddressEvent.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpAddressEvent.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpAddressEvent.java
deleted file mode 100644
index 500d224..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpAddressEvent.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.tcp;
-
-import org.apache.kerby.transport.event.AddressEvent;
-
-import java.net.InetSocketAddress;
-
-public class TcpAddressEvent {
-
- public static AddressEvent createAddressBindEvent(InetSocketAddress address) {
- return new AddressEvent(address, TcpEventType.ADDRESS_BIND);
- }
-
- public static AddressEvent createAddressConnectEvent(InetSocketAddress address) {
- return new AddressEvent(address, TcpEventType.ADDRESS_CONNECT);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpConnector.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpConnector.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpConnector.java
deleted file mode 100644
index e460961..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpConnector.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.tcp;
-
-import org.apache.kerby.event.AbstractEventHandler;
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.transport.Connector;
-import org.apache.kerby.transport.Transport;
-import org.apache.kerby.transport.event.AddressEvent;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
-
-public class TcpConnector extends Connector {
-
- public TcpConnector(StreamingDecoder streamingDecoder) {
- this(new TcpTransportHandler(streamingDecoder));
- }
-
- public TcpConnector(TcpTransportHandler transportHandler) {
- super(transportHandler);
-
- setEventHandler(new AbstractEventHandler() {
- @Override
- protected void doHandle(Event event) throws Exception {
- if (event.getEventType() == TcpEventType.ADDRESS_CONNECT) {
- doConnect((AddressEvent) event);
- }
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return new EventType[] {
- TcpEventType.ADDRESS_CONNECT
- };
- }
- });
- }
-
- @Override
- protected void doConnect(InetSocketAddress sa) {
- AddressEvent event = TcpAddressEvent.createAddressConnectEvent(sa);
- dispatch(event);
- }
-
- private void doConnect(AddressEvent event) throws IOException {
- SocketChannel channel = SocketChannel.open();
- channel.configureBlocking(false);
- channel.connect(event.getAddress());
- channel.register(selector,
- SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE);
- }
-
- @Override
- protected void dealKey(SelectionKey selectionKey) throws IOException {
- if (selectionKey.isConnectable()) {
- doConnect(selectionKey);
- } else {
- super.dealKey(selectionKey);
- }
- }
-
- private void doConnect(SelectionKey key) throws IOException {
- SocketChannel channel = (SocketChannel) key.channel();
- if (channel.isConnectionPending()) {
- channel.finishConnect();
- }
-
- Transport transport = new TcpTransport(channel,
- ((TcpTransportHandler) transportHandler).getStreamingDecoder());
- channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE, transport);
- onNewTransport(transport);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpEventType.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpEventType.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpEventType.java
deleted file mode 100644
index e754fa5..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpEventType.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.tcp;
-
-import org.apache.kerby.event.EventType;
-
-public enum TcpEventType implements EventType {
- ADDRESS_BIND,
- ADDRESS_CONNECT
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java
deleted file mode 100644
index 57705ca..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.tcp;
-
-import org.apache.kerby.transport.Transport;
-import org.apache.kerby.transport.buffer.BufferPool;
-import org.apache.kerby.transport.buffer.RecvBuffer;
-import org.apache.kerby.transport.event.MessageEvent;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-public class TcpTransport extends Transport {
-
- private SocketChannel channel;
-
- private StreamingDecoder streamingDecoder;
-
- private RecvBuffer recvBuffer;
-
- public TcpTransport(SocketChannel channel,
- StreamingDecoder streamingDecoder) throws IOException {
- super((InetSocketAddress) channel.getRemoteAddress());
- this.channel = channel;
- this.streamingDecoder = streamingDecoder;
-
- this.recvBuffer = new RecvBuffer();
- }
-
- @Override
- protected void sendOutMessage(ByteBuffer message) throws IOException {
- channel.write(message);
- }
-
- public void onReadable() throws IOException {
- ByteBuffer writeBuffer = BufferPool.allocate(65536);
- if (channel.read(writeBuffer) <= 0) {
- BufferPool.release(writeBuffer);
- return;
- }
-
- writeBuffer.flip();
- recvBuffer.write(writeBuffer);
-
- WithReadDataHander rdHandler = new WithReadDataHander();
- rdHandler.handle();
- }
-
- class WithReadDataHander implements DecodingCallback {
- private ByteBuffer streamingBuffer;
-
- @Override
- public void onMessageComplete(int messageLength, int adjustOffset) {
- ByteBuffer message = null;
-
- int remaining = streamingBuffer.remaining();
- if (remaining == messageLength) {
- message = streamingBuffer;
- } else if (remaining > messageLength) {
- message = streamingBuffer.duplicate();
- int newLimit = streamingBuffer.position() + messageLength;
- message.limit(newLimit);
-
- streamingBuffer.position(newLimit);
- recvBuffer.writeFirst(streamingBuffer);
- }
-
- if (message != null) {
- if (adjustOffset > 0) {
- message.position(message.position() + adjustOffset);
- }
- dispatcher.dispatch(MessageEvent.createInboundMessageEvent(
- TcpTransport.this, message));
- }
- }
-
- @Override
- public void onMoreDataNeeded() {
- recvBuffer.writeFirst(streamingBuffer);
- }
-
- @Override
- public void onMoreDataNeeded(int needDataLength) {
- recvBuffer.writeFirst(streamingBuffer);
- }
-
- public void handle() {
- if (recvBuffer.isEmpty()) {
- return;
- }
-
- streamingBuffer = recvBuffer.readMostBytes();
-
- streamingDecoder.decode(streamingBuffer.duplicate(), this);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransportHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransportHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransportHandler.java
deleted file mode 100644
index ad010ed..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransportHandler.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.tcp;
-
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.transport.Transport;
-import org.apache.kerby.transport.event.TransportEventType;
-import org.apache.kerby.transport.TransportHandler;
-import org.apache.kerby.transport.event.TransportEvent;
-
-import java.io.IOException;
-import java.nio.channels.SelectionKey;
-
-public class TcpTransportHandler extends TransportHandler {
-
- private StreamingDecoder streamingDecoder;
-
- public TcpTransportHandler(StreamingDecoder streamingDecoder) {
- this.streamingDecoder = streamingDecoder;
- }
-
- public StreamingDecoder getStreamingDecoder() {
- return streamingDecoder;
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return new TransportEventType[] {
- TransportEventType.TRANSPORT_READABLE,
- TransportEventType.TRANSPORT_WRITABLE
- };
- }
-
- @Override
- protected void doHandle(Event event) throws Exception {
- EventType eventType = event.getEventType();
- TransportEvent te = (TransportEvent) event;
- Transport transport = te.getTransport();
- if (eventType == TransportEventType.TRANSPORT_READABLE) {
- transport.onReadable();
- } else if (eventType == TransportEventType.TRANSPORT_WRITABLE) {
- transport.onWriteable();
- }
- }
-
- @Override
- public void helpHandleSelectionKey(SelectionKey selectionKey) throws IOException {
- if (selectionKey.isReadable()) {
- selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
- TcpTransport transport = (TcpTransport) selectionKey.attachment();
- dispatch(TransportEvent.createReadableTransportEvent(transport));
- } else if (selectionKey.isWritable()) {
- selectionKey.interestOps(SelectionKey.OP_READ);
- TcpTransport transport = (TcpTransport) selectionKey.attachment();
- dispatch(TransportEvent.createWritableTransportEvent(transport));
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpAcceptor.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpAcceptor.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpAcceptor.java
deleted file mode 100644
index 974f871..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpAcceptor.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.udp;
-
-import org.apache.kerby.event.AbstractEventHandler;
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.transport.Acceptor;
-import org.apache.kerby.transport.event.AddressEvent;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.SelectionKey;
-
-public class UdpAcceptor extends Acceptor {
-
- private DatagramChannel serverChannel;
-
- public UdpAcceptor() {
- this(new UdpTransportHandler());
- }
-
- public UdpAcceptor(UdpTransportHandler udpTransportHandler) {
- super(udpTransportHandler);
-
- setEventHandler(new AbstractEventHandler() {
- @Override
- protected void doHandle(Event event) throws Exception {
- if (event.getEventType() == UdpEventType.ADDRESS_BIND) {
- doBind((AddressEvent) event);
- }
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return new EventType[] {
- UdpEventType.ADDRESS_BIND
- };
- }
- });
- }
-
- @Override
- protected void doListen(InetSocketAddress socketAddress) {
- AddressEvent event = UdpAddressEvent.createAddressBindEvent(socketAddress);
- dispatch(event);
- }
-
- private void doBind(AddressEvent event) throws IOException {
- serverChannel = DatagramChannel.open();
- serverChannel.configureBlocking(false);
- serverChannel.bind(event.getAddress());
- serverChannel.register(selector, SelectionKey.OP_READ);
- }
-
- @Override
- public void stop() {
- super.stop();
-
- try {
- serverChannel.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpAddressEvent.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpAddressEvent.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpAddressEvent.java
deleted file mode 100644
index b29100e..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpAddressEvent.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.udp;
-
-import org.apache.kerby.transport.event.AddressEvent;
-
-import java.net.InetSocketAddress;
-
-public class UdpAddressEvent {
-
- public static AddressEvent createAddressBindEvent(InetSocketAddress address) {
- return new AddressEvent(address, UdpEventType.ADDRESS_BIND);
- }
-
- public static AddressEvent createAddressConnectEvent(InetSocketAddress address) {
- return new AddressEvent(address, UdpEventType.ADDRESS_CONNECT);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpChannelEvent.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpChannelEvent.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpChannelEvent.java
deleted file mode 100644
index e5dd7b2..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpChannelEvent.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.udp;
-
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-
-import java.nio.channels.DatagramChannel;
-
-public class UdpChannelEvent extends Event {
-
- private DatagramChannel channel;
-
- private UdpChannelEvent(DatagramChannel channel, EventType eventType) {
- super(eventType);
- this.channel = channel;
- }
-
- public DatagramChannel getChannel() {
- return channel;
- }
-
- public static UdpChannelEvent makeWritableChannelEvent(DatagramChannel channel) {
- return new UdpChannelEvent(channel, UdpEventType.CHANNEL_WRITABLE);
- }
-
- public static UdpChannelEvent makeReadableChannelEvent(DatagramChannel channel) {
- return new UdpChannelEvent(channel, UdpEventType.CHANNEL_READABLE);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpConnector.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpConnector.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpConnector.java
deleted file mode 100644
index 9234a8c..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpConnector.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.udp;
-
-import org.apache.kerby.event.AbstractEventHandler;
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.transport.Connector;
-import org.apache.kerby.transport.event.AddressEvent;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.SelectionKey;
-
-public class UdpConnector extends Connector {
-
- public UdpConnector() {
- this(new UdpTransportHandler());
- }
-
- public UdpConnector(UdpTransportHandler transportHandler) {
- super(transportHandler);
-
- setEventHandler(new AbstractEventHandler() {
- @Override
- protected void doHandle(Event event) throws Exception {
- if (event.getEventType() == UdpEventType.ADDRESS_CONNECT) {
- doConnect((AddressEvent) event);
- }
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return new EventType[] {
- UdpEventType.ADDRESS_CONNECT
- };
- }
- });
- }
-
- @Override
- protected void doConnect(InetSocketAddress sa) {
- AddressEvent event = UdpAddressEvent.createAddressConnectEvent(sa);
- dispatch(event);
- }
-
- private void doConnect(AddressEvent event) throws IOException {
- InetSocketAddress address = event.getAddress();
- DatagramChannel channel = DatagramChannel.open();
- channel.configureBlocking(false);
- channel.connect(address);
-
- channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
-
- UdpTransport transport = new UdpTransport(channel, address);
- onNewTransport(transport);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpEventType.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpEventType.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpEventType.java
deleted file mode 100644
index d291f75..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpEventType.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.udp;
-
-import org.apache.kerby.event.EventType;
-
-public enum UdpEventType implements EventType {
- ADDRESS_BIND,
- ADDRESS_CONNECT,
- CHANNEL_WRITABLE,
- CHANNEL_READABLE
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpTransport.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpTransport.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpTransport.java
deleted file mode 100644
index fe11a64..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpTransport.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.udp;
-
-import org.apache.kerby.transport.Transport;
-import org.apache.kerby.transport.buffer.TransBuffer;
-import org.apache.kerby.transport.event.MessageEvent;
-import org.apache.kerby.transport.event.TransportEvent;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.DatagramChannel;
-
-public class UdpTransport extends Transport {
- private DatagramChannel channel;
-
- protected TransBuffer recvBuffer;
-
- public UdpTransport(DatagramChannel channel,
- InetSocketAddress remoteAddress) {
- super(remoteAddress);
- this.channel = channel;
- this.recvBuffer = new TransBuffer();
- }
-
- protected void onRecvData(ByteBuffer data) {
- if (data != null) {
- recvBuffer.write(data);
- dispatcher.dispatch(TransportEvent.createReadableTransportEvent(this));
- }
- }
-
- @Override
- public void onReadable() throws IOException {
- super.onReadable();
-
- if (! recvBuffer.isEmpty()) {
- ByteBuffer message = recvBuffer.read();
- dispatcher.dispatch(MessageEvent.createInboundMessageEvent(this, message));
- }
- }
-
- @Override
- protected void sendOutMessage(ByteBuffer message) throws IOException {
- channel.send(message, getRemoteAddress());
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpTransportHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpTransportHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpTransportHandler.java
deleted file mode 100644
index fc02bf5..0000000
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/udp/UdpTransportHandler.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.transport.udp;
-
-import org.apache.kerby.event.Event;
-import org.apache.kerby.event.EventType;
-import org.apache.kerby.transport.Transport;
-import org.apache.kerby.transport.TransportHandler;
-import org.apache.kerby.transport.event.TransportEvent;
-import org.apache.kerby.transport.event.TransportEventType;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.SelectionKey;
-import java.util.HashMap;
-import java.util.Map;
-
-public class UdpTransportHandler extends TransportHandler {
-
- protected Map<InetSocketAddress, UdpTransport> transports =
- new HashMap<InetSocketAddress, UdpTransport>();
-
- @Override
- public EventType[] getInterestedEvents() {
- return new EventType[] {
- UdpEventType.CHANNEL_READABLE,
- TransportEventType.TRANSPORT_WRITABLE,
- TransportEventType.TRANSPORT_READABLE,
- TransportEventType.NEW_TRANSPORT
- };
- }
-
- @Override
- protected void doHandle(Event event) throws Exception {
- EventType eventType = event.getEventType();
- if (eventType == UdpEventType.CHANNEL_READABLE) {
- UdpChannelEvent ce = (UdpChannelEvent) event;
- DatagramChannel channel = ce.getChannel();
- doRead(channel);
- } else if (eventType == TransportEventType.TRANSPORT_READABLE) {
- TransportEvent te = (TransportEvent) event;
- Transport transport = te.getTransport();
- transport.onReadable();
- } else if (eventType == TransportEventType.TRANSPORT_WRITABLE) {
- TransportEvent te = (TransportEvent) event;
- Transport transport = te.getTransport();
- transport.onWriteable();
- } else if (eventType == TransportEventType.NEW_TRANSPORT) {
- TransportEvent te = (TransportEvent) event;
- Transport transport = te.getTransport();
- if (transport instanceof UdpTransport) {
- InetSocketAddress remoteAddress = transport.getRemoteAddress();
- if (! transports.containsKey(remoteAddress)) {
- transports.put(remoteAddress, (UdpTransport) transport);
- }
- }
- }
- }
-
- private void doRead(DatagramChannel channel) throws IOException {
- ByteBuffer recvBuffer = ByteBuffer.allocate(65536); // to optimize
- InetSocketAddress fromAddress = (InetSocketAddress) channel.receive(recvBuffer);
- if (fromAddress != null) {
- recvBuffer.flip();
- UdpTransport transport = transports.get(fromAddress);
- if (transport == null) {
- // should be from acceptor
- transport = new UdpTransport(channel, fromAddress);
- transport.setDispatcher(getDispatcher());
- dispatch(TransportEvent.createNewTransportEvent(transport));
- }
- transport.onRecvData(recvBuffer);
- }
- }
-
- @Override
- public void helpHandleSelectionKey(SelectionKey selectionKey) throws IOException {
- DatagramChannel channel =
- (DatagramChannel) selectionKey.channel();
-
- if (selectionKey.isReadable()) {
- dispatch(UdpChannelEvent.makeReadableChannelEvent(channel));
- } else if (selectionKey.isWritable()) {
- dispatch(UdpChannelEvent.makeWritableChannelEvent(channel));
- }
- // Udp channel is always writable, so not usable
- selectionKey.interestOps(SelectionKey.OP_READ);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/735686ad/lib/kerby-event/src/test/java/org/apache/kerby/event/NetworkUtil.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/NetworkUtil.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/NetworkUtil.java
deleted file mode 100644
index 7e3e22e..0000000
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/NetworkUtil.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.kerby.event;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-
-/**
- * Some network and event testing utilities.
- */
-public class NetworkUtil {
-
- /**
- * Get a server socket point for testing usage, either TCP or UDP.
- * @return server socket point
- */
- public static int getServerPort() {
- int serverPort = 0;
-
- try {
- ServerSocket serverSocket = new ServerSocket(0);
- serverPort = serverSocket.getLocalPort();
- serverSocket.close();
- } catch (IOException e) {
- throw new RuntimeException("Failed to get a server socket point");
- }
-
- return serverPort;
- }
-}