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/01/22 22:48:20 UTC
[41/45] directory-kerberos git commit: DIRKRB-149 New layout
structure with the new name "Apache Kerby"
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-config/src/main/java/org/apache/haox/config/Resource.java
----------------------------------------------------------------------
diff --git a/contrib/haox-config/src/main/java/org/apache/haox/config/Resource.java b/contrib/haox-config/src/main/java/org/apache/haox/config/Resource.java
deleted file mode 100644
index 090c381..0000000
--- a/contrib/haox-config/src/main/java/org/apache/haox/config/Resource.java
+++ /dev/null
@@ -1,119 +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.haox.config;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Map;
-import java.util.Properties;
-
-public class Resource {
- public static enum Format {
- XML_FILE(XmlConfigLoader.class),
- INI_FILE(IniConfigLoader.class),
- JSON_FILE(JsonConfigLoader.class),
- PROPERTIES_FILE(PropertiesFileConfigLoader.class),
- MAP(MapConfigLoader.class),
- PROPERTIES(PropertiesConfigLoader.class);
-
- private Class<? extends ConfigLoader> loaderClass;
-
- private Format(Class<? extends ConfigLoader> loaderClass) {
- this.loaderClass = loaderClass;
- }
-
- public Class<? extends ConfigLoader> getLoaderClass() {
- return loaderClass;
- }
- }
-
- private String name;
- private Object resource;
- private Format format;
-
- public static Resource createXmlResource(File xmlFile) throws IOException {
- return new Resource(xmlFile.getName(), xmlFile, Format.XML_FILE);
- }
-
- public static Resource createIniResource(File iniFile) throws IOException {
- return new Resource(iniFile.getName(), iniFile, Format.INI_FILE);
- }
-
- public static Resource createJsonResource(File jsonFile) throws IOException {
- return new Resource(jsonFile.getName(), jsonFile, Format.JSON_FILE);
- }
-
- public static Resource createXmlResource(URL xmlUrl) throws IOException {
- return new Resource(xmlUrl, Format.XML_FILE);
- }
-
- public static Resource createIniResource(URL iniUrl) throws IOException {
- return new Resource(iniUrl, Format.INI_FILE);
- }
-
- public static Resource createJsonResource(URL jsonUrl) throws IOException {
- return new Resource(jsonUrl, Format.JSON_FILE);
- }
-
- public static Resource createMapResource(Map<String,String> mapConfig) {
- return new Resource("mapConfig", mapConfig, Format.MAP);
- }
-
- public static Resource createPropertiesFileResource(File propFile) throws IOException {
- return new Resource(propFile.getName(), propFile, Format.PROPERTIES_FILE);
- }
-
- public static Resource createPropertiesResource(Properties propertiesConfig) {
- return new Resource("propConfig", propertiesConfig, Format.PROPERTIES);
- }
-
- private Resource(String name, File resourceFile, Format format) throws FileNotFoundException {
- this(name, new FileInputStream(resourceFile), format);
- }
-
- private Resource(URL resourceUrl, Format format) throws IOException {
- this(resourceUrl.toString(), resourceUrl.openStream(), format);
- }
-
- private Resource(String name, Object resourceStream, Format format) {
- this.name = name;
- this.resource = resourceStream;
- this.format = format;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public Object getResource() {
- return resource;
- }
-
- public Format getFormat() {
- return format;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-config/src/main/java/org/apache/haox/config/XmlConfigLoader.java
----------------------------------------------------------------------
diff --git a/contrib/haox-config/src/main/java/org/apache/haox/config/XmlConfigLoader.java b/contrib/haox-config/src/main/java/org/apache/haox/config/XmlConfigLoader.java
deleted file mode 100644
index b507363..0000000
--- a/contrib/haox-config/src/main/java/org/apache/haox/config/XmlConfigLoader.java
+++ /dev/null
@@ -1,159 +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.haox.config;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.*;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-public class XmlConfigLoader extends ConfigLoader {
- private static final Logger logger = LoggerFactory.getLogger(Config.class);
-
- @Override
- protected void loadConfig(ConfigImpl config, Resource resource) throws Exception {
- Element doc = loadResourceDocument(resource);
- loadConfig((ConfigImpl) config, doc);
- }
-
- private Element loadResourceDocument(Resource resource) throws Exception {
- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-
- docBuilderFactory.setIgnoringComments(true);
- docBuilderFactory.setNamespaceAware(true);
- try {
- docBuilderFactory.setXIncludeAware(true);
- } catch (UnsupportedOperationException e) {
- logger.error("Failed to set setXIncludeAware(true) for parser", e);
- }
- DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
- InputStream is = (InputStream) resource.getResource();
- Document doc = null;
- try {
- doc = builder.parse(is);
- } finally {
- is.close();
- }
-
- Element root = doc.getDocumentElement();
- validateConfig(root);
-
- return root;
- }
-
- private boolean validateConfig(Element root) {
- boolean valid = false;
-
- if ("config".equals(root.getTagName())) {
- valid = true;
- } else {
- logger.error("bad conf element: top-level element not <configuration>");
- }
-
- return valid;
- }
-
- private void loadConfig(ConfigImpl conifg, Element element) {
- String name;
- ConfigObject value;
-
- NodeList props = element.getChildNodes();
- for (int i = 0; i < props.getLength(); i++) {
- Node subNode = props.item(i);
- if (!(subNode instanceof Element)) {
- continue;
- }
-
- Element prop = (Element)subNode;
- name = getElementName(prop);
- if (name == null) {
- continue;
- }
-
- value = null;
- String tagName = prop.getTagName();
- if ("property".equals(tagName) && prop.hasChildNodes()) {
- value = loadProperty(prop);
- } else if ("config".equals(tagName) && prop.hasChildNodes()) {
- ConfigImpl cfg = new ConfigImpl(name);
- loadConfig(cfg, prop);
- value = new ConfigObject(cfg);
- }
-
- if (name != null) {
- conifg.set(name, value);
- }
- }
- }
-
- private static ConfigObject loadProperty(Element ele) {
- String value = null;
- if (ele.getFirstChild() instanceof Text) {
- value = ((Text)ele.getFirstChild()).getData();
- return new ConfigObject(value);
- }
-
- ConfigObject result = null;
- NodeList nodes = ele.getChildNodes();
- List<String> values = new ArrayList<String>(nodes.getLength());
- for (int i = 0; i < nodes.getLength(); i++) {
- value = null;
- Node valueNode = nodes.item(i);
- if (!(valueNode instanceof Element))
- continue;
-
- Element valueEle = (Element)valueNode;
- if ("value".equals(valueEle.getTagName()) && valueEle.hasChildNodes()) {
- value = ((Text)valueEle.getFirstChild()).getData();
- }
-
- if (value != null) {
- values.add(value);
- }
- }
- return new ConfigObject(values);
- }
-
- private static String getElementName(Element ele) {
- String name, value;
- Node node;
- Attr attr;
-
- NamedNodeMap nnm = ele.getAttributes();
- for (int i = 0; i < nnm.getLength(); ++i) {
- node = nnm.item(i);
- if (!(node instanceof Attr))
- continue;
- attr = (Attr) node;
- name = attr.getName();
- value = attr.getValue();
-
- if ("name".equals(name)) {
- return value;
- }
- }
- return null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-config/src/test/java/org/apache/haox/config/ConfTest.java
----------------------------------------------------------------------
diff --git a/contrib/haox-config/src/test/java/org/apache/haox/config/ConfTest.java b/contrib/haox-config/src/test/java/org/apache/haox/config/ConfTest.java
deleted file mode 100644
index 592ed3d..0000000
--- a/contrib/haox-config/src/test/java/org/apache/haox/config/ConfTest.java
+++ /dev/null
@@ -1,135 +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.haox.config;
-
-import org.apache.haox.config.Conf;
-import org.apache.haox.config.ConfigKey;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * The test is base on the Conf level.
- * We hope users use the Conf object only, and don't need to care about its internal implementation.
- */
-public class ConfTest {
-
- @Test
- public void testMapConfig() {
- String strProp = "hello";
- Integer intProp = 123456;
- Boolean boolProp = true;
- Map<String, String> mapConfig = new HashMap<String, String>();
- mapConfig.put("strProp", strProp);
- mapConfig.put("intProp", String.valueOf(intProp));
- mapConfig.put("boolProp", String.valueOf(boolProp));
-
- Conf conf = new Conf();
- conf.addMapConfig(mapConfig);
- Assert.assertEquals(conf.getString("strProp"), strProp);
- Assert.assertEquals(conf.getInt("intProp"), intProp);
- Assert.assertEquals(conf.getBoolean("boolProp"), boolProp);
- }
-
- @Test
- public void testPropertiesConfig() {
- String strProp = "hello";
- Integer intProp = 123456;
- Boolean boolProp = true;
- Properties properties = new Properties();
- properties.setProperty("strProp", strProp);
- properties.setProperty("intProp", String.valueOf(intProp));
- properties.setProperty("boolProp", String.valueOf(boolProp));
-
- Conf conf = new Conf();
- conf.addPropertiesConfig(properties);
- Assert.assertEquals(conf.getString("strProp"), strProp);
- Assert.assertEquals(conf.getInt("intProp"), intProp);
- Assert.assertEquals(conf.getBoolean("boolProp"), boolProp);
- }
-
- /**
- * Test for whether can get right value form the conf which contains many config resources.
- */
- @Test
- public void testMixedConfig() {
- String mapStrProp = "hello map";
- Integer intProp = 123456;
- Map<String, String> mapConfig = new HashMap<String, String>();
- mapConfig.put("mapStrProp", mapStrProp);
- mapConfig.put("intProp", String.valueOf(intProp));
-
- String propertiesStrProp = "hello properties";
- Boolean boolProp = true;
- Properties properties = new Properties();
- properties.setProperty("propertiesStrProp", propertiesStrProp);
- properties.setProperty("boolProp", String.valueOf(boolProp));
-
- Conf conf = new Conf();
- conf.addMapConfig(mapConfig);
- conf.addPropertiesConfig(properties);
- Assert.assertEquals(conf.getConfig("mapConfig"), null);
- Assert.assertEquals(conf.getString("mapStrProp"), mapStrProp);
- Assert.assertEquals(conf.getString("propertiesStrProp"), propertiesStrProp);
- Assert.assertEquals(conf.getInt("intProp"), intProp);
- Assert.assertEquals(conf.getBoolean("boolProp"), boolProp);
- }
-
- static enum TestConfKey implements ConfigKey {
- ADDRESS("127.0.0.1"),
- PORT(8015),
- ENABLE(false);
-
- private Object defaultValue;
-
- private TestConfKey(Object defaultValue) {
- this.defaultValue = defaultValue;
- }
-
- @Override
- public String getPropertyKey() {
- return name().toLowerCase();
- }
-
- @Override
- public Object getDefaultValue() {
- return this.defaultValue;
- }
- }
-
- @Test
- public void testConfKey() {
- Conf conf = new Conf();
- Assert.assertEquals(conf.getString(TestConfKey.ADDRESS),
- TestConfKey.ADDRESS.getDefaultValue());
- Map<String, String> mapConfig = new HashMap<String, String>();
- String myAddress = "www.google.com";
- mapConfig.put(TestConfKey.ADDRESS.getPropertyKey(), myAddress);
- conf.addMapConfig(mapConfig);
- Assert.assertEquals(conf.getString(TestConfKey.ADDRESS), myAddress);
- Assert.assertEquals(conf.getInt(TestConfKey.PORT),
- TestConfKey.PORT.getDefaultValue());
- Assert.assertEquals(conf.getBoolean(TestConfKey.ENABLE),
- TestConfKey.ENABLE.getDefaultValue());
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-config/src/test/java/org/apache/haox/config/ConfigImplTest.java
----------------------------------------------------------------------
diff --git a/contrib/haox-config/src/test/java/org/apache/haox/config/ConfigImplTest.java b/contrib/haox-config/src/test/java/org/apache/haox/config/ConfigImplTest.java
deleted file mode 100644
index fd491e2..0000000
--- a/contrib/haox-config/src/test/java/org/apache/haox/config/ConfigImplTest.java
+++ /dev/null
@@ -1,62 +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.haox.config;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * The test is on ConfigImpl level.
- * ConfigImpl is the internal implementation of Conf, only visual by developers.
- */
-public class ConfigImplTest {
-
- /**
- * Test for section config support.
- */
- @Test
- public void testSectionConfig() {
- ConfigImpl rootConfig = new ConfigImpl(null);
- rootConfig.set("globalConfig", "true");
-
- ConfigImpl sectionA = new ConfigImpl("libdefaults");
- rootConfig.set("libdefaults", sectionA);
- sectionA.set("default_realm", "EXAMPLE.COM");
- sectionA.set("forwardable", "true");
- sectionA.set("dns_lookup_realm", "false");
-
- ConfigImpl sectionB = new ConfigImpl("logging");
- rootConfig.set("logging", sectionB);
- sectionB.set("kdc", "FILE:/var/log/krb5kdc.log");
-
- Assert.assertEquals(rootConfig.getString("globalConfig"), "true");
- Assert.assertEquals(rootConfig.getString("default_realm"), null);
-
- Config subA = rootConfig.getConfig("libdefaults");
- Assert.assertEquals(subA.getString("default_realm"), "EXAMPLE.COM");
- Assert.assertEquals(subA.getString("globalConfig"), null);
- Assert.assertEquals(subA.getString("kdc"), null);
-
- Config subB = rootConfig.getConfig("logging");
- Assert.assertEquals(subB.getString("kdc"), "FILE:/var/log/krb5kdc.log");
- Assert.assertEquals(subB.getString("globalConfig"), null);
- Assert.assertEquals(subB.getBoolean("forwardable"), null);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-config/src/test/java/org/apache/haox/config/IniConfigTest.java
----------------------------------------------------------------------
diff --git a/contrib/haox-config/src/test/java/org/apache/haox/config/IniConfigTest.java b/contrib/haox-config/src/test/java/org/apache/haox/config/IniConfigTest.java
deleted file mode 100644
index bd2f93b..0000000
--- a/contrib/haox-config/src/test/java/org/apache/haox/config/IniConfigTest.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.haox.config;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-
-public class IniConfigTest {
-
- private final static String TEST_DIR = new File(System.getProperty(
- "test.build.data", "/tmp")).getAbsolutePath();
- private final static File TEST_FILE = new File(TEST_DIR, "test-ini-config");
-
- /**
- * Build a INI format configuration file.
- */
- private void buildFile() throws IOException {
- PrintWriter out = new PrintWriter(new FileWriter(TEST_FILE));
- out.println("#note = notenote");
- out.println("default = FILE:/var/log/krb5libs.log");
- out.println("kdc = FILE:/var/log/krb5kdc.log");
- out.println("admin_server = FILE:/var/log/kadmind.log");
- out.println("[libdefaults]");
- out.println("default_realm = EXAMPLE.COM");
- out.println("dns_lookup_realm = false");
- out.println("dns_lookup_kdc = false");
- out.println("ticket_lifetime = 24h");
- out.println("renew_lifetime = 7d");
- out.println("forwardable = true");
- out.println("[lib1]");
- out.println("default_realm = EXAMPLE.COM1");
- out.println("dns_lookup_realm = true");
- out.close();
- }
-
- @Test
- public void testIniConfig() throws IOException {
- buildFile();
-
- Conf conf = new Conf();
- conf.addIniConfig(TEST_FILE);
-
- Assert.assertEquals(conf.getString("default"), "FILE:/var/log/krb5libs.log");
- Assert.assertEquals(conf.getString("#note"), null);//Comments should be ignored when loading.
-
- Config config = conf.getConfig("libdefaults");
- Assert.assertFalse(config.getBoolean("dns_lookup_realm"));
- Assert.assertTrue(config.getBoolean("forwardable"));
-
- Config config1 = conf.getConfig("lib1");
- Assert.assertTrue(config1.getBoolean("dns_lookup_realm"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/README
----------------------------------------------------------------------
diff --git a/contrib/haox-event/README b/contrib/haox-event/README
deleted file mode 100644
index cb3b88a..0000000
--- a/contrib/haox-event/README
+++ /dev/null
@@ -1 +0,0 @@
-An event driven application framework with mixed (TCP, UDP) x (connector, acceptor) supported.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/haox-event/pom.xml b/contrib/haox-event/pom.xml
deleted file mode 100644
index 5e3b215..0000000
--- a/contrib/haox-event/pom.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed 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. See accompanying LICENSE file.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <artifactId>contrib</artifactId>
- <groupId>org.haox</groupId>
- <version>1.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>haox-event</artifactId>
-
- <name>Haox Event</name>
- <description>Haox Event and Transport facilities for both client and server</description>
-
- <dependencies>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/AbstractEventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/AbstractEventHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/event/AbstractEventHandler.java
deleted file mode 100644
index 517b585..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/AbstractEventHandler.java
+++ /dev/null
@@ -1,55 +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.haox.event;
-
-public abstract class AbstractEventHandler implements EventHandler {
-
- private Dispatcher dispatcher;
-
- public AbstractEventHandler() {
-
- }
-
- protected void dispatch(Event event) {
- dispatcher.dispatch(event);
- }
-
- @Override
- public Dispatcher getDispatcher() {
- return dispatcher;
- }
-
- @Override
- public void setDispatcher(Dispatcher dispatcher) {
- this.dispatcher = dispatcher;
- }
-
- @Override
- public void handle(Event event) {
- try {
- doHandle(event);
- } catch (Exception e) {
- throw new RuntimeException(event.toString(), e);
- }
- }
-
- protected abstract void doHandle(Event event) throws Exception;
-}
-
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/AbstractInternalEventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/AbstractInternalEventHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/event/AbstractInternalEventHandler.java
deleted file mode 100644
index f0bc944..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/AbstractInternalEventHandler.java
+++ /dev/null
@@ -1,66 +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.haox.event;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-public abstract class AbstractInternalEventHandler extends AbstractEventHandler
- implements InternalEventHandler {
-
- private int id = -1;
- protected EventHandler handler;
-
- private static AtomicInteger idGen = new AtomicInteger(1);
-
- public AbstractInternalEventHandler() {
- super();
-
- this.id = idGen.getAndIncrement();
-
- init();
- }
-
- public AbstractInternalEventHandler(EventHandler handler) {
- this();
-
- this.handler = handler;
- }
-
- protected void setEventHandler(EventHandler handler) {
- this.handler = handler;
- }
-
- @Override
- public int id() {
- return id;
- }
-
- public abstract void init();
-
- protected void process(Event event) {
- handler.handle(event);
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return handler.getInterestedEvents();
- }
-}
-
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/BufferedEventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/BufferedEventHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/event/BufferedEventHandler.java
deleted file mode 100644
index 6d9da9c..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/BufferedEventHandler.java
+++ /dev/null
@@ -1,53 +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.haox.event;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-
-/**
- * An EventHandler wrapper buffering events and processing them later
- */
-public abstract class BufferedEventHandler extends AbstractInternalEventHandler {
-
- protected BlockingQueue<Event> eventQueue;
-
- public BufferedEventHandler(EventHandler handler) {
- super(handler);
- }
-
- public BufferedEventHandler() {
- super();
- }
-
- @Override
- public void init() {
- this.eventQueue = new ArrayBlockingQueue<Event>(2);
- }
-
- @Override
- protected void doHandle(Event event) throws Exception {
- try {
- eventQueue.put(event);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/Dispatcher.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/Dispatcher.java b/contrib/haox-event/src/main/java/org/apache/haox/event/Dispatcher.java
deleted file mode 100644
index e3387c5..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/Dispatcher.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.haox.event;
-
-public interface Dispatcher {
-
- public void dispatch(Event event);
-
- public void register(EventHandler handler);
-
- public void register(InternalEventHandler internalHandler);
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/Event.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/Event.java b/contrib/haox-event/src/main/java/org/apache/haox/event/Event.java
deleted file mode 100644
index 19d405c..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/Event.java
+++ /dev/null
@@ -1,43 +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.haox.event;
-
-public class Event {
-
- private EventType eventType;
- private Object eventData;
-
- public Event(EventType eventType) {
- this.eventType = eventType;
- }
-
- public Event(EventType eventType, Object eventData) {
- this.eventType = eventType;
- this.eventData = eventData;
- }
-
- public EventType getEventType() {
- return eventType;
- }
-
- public Object getEventData() {
- return eventData;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/EventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/EventHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/event/EventHandler.java
deleted file mode 100644
index d84ead9..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/EventHandler.java
+++ /dev/null
@@ -1,31 +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.haox.event;
-
-public interface EventHandler {
-
- public void handle(Event event);
-
- public EventType[] getInterestedEvents();
-
- public Dispatcher getDispatcher();
-
- public void setDispatcher(Dispatcher dispatcher);
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/EventHub.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/EventHub.java b/contrib/haox-event/src/main/java/org/apache/haox/event/EventHub.java
deleted file mode 100644
index 6a4d989..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/EventHub.java
+++ /dev/null
@@ -1,192 +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.haox.event;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-public class EventHub implements Dispatcher {
-
- private enum BuiltInEventType implements EventType {
- STOP,
- ALL
- }
-
- private boolean started = false;
-
- private Map<Integer, InternalEventHandler> handlers =
- new ConcurrentHashMap<Integer, InternalEventHandler>();
-
- private Map<EventType, Set<Integer>> eventHandlersMap =
- new ConcurrentHashMap<EventType, Set<Integer>>();
-
- private InternalEventHandler builtInHandler;
-
- class BuiltInEventHandler extends AbstractEventHandler {
- public BuiltInEventHandler() {
- super();
- }
-
- @Override
- protected void doHandle(Event event) {
-
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return BuiltInEventType.values();
- }
- }
-
- public EventHub() {
- init();
- }
-
- private void init() {
- EventHandler eh = new BuiltInEventHandler();
- builtInHandler = new ExecutedEventHandler(eh);
- register(builtInHandler);
- }
-
- @Override
- public void dispatch(Event event) {
- process(event);
- }
-
- @Override
- public void register(EventHandler handler) {
- handler.setDispatcher(this);
- InternalEventHandler ieh = new ExecutedEventHandler(handler);
- register(ieh);
- }
-
- @Override
- public void register(InternalEventHandler handler) {
- handler.setDispatcher(this);
- handler.init();
- handlers.put(handler.id(), handler);
-
- if (started) {
- handler.start();
- }
-
- EventType[] interestedEvents = handler.getInterestedEvents();
- Set<Integer> tmpHandlers;
- for (EventType eventType : interestedEvents) {
- if (eventHandlersMap.containsKey(eventType)) {
- tmpHandlers = eventHandlersMap.get(eventType);
- } else {
- tmpHandlers = new HashSet<Integer>();
- eventHandlersMap.put(eventType, tmpHandlers);
- }
- tmpHandlers.add(handler.id());
- }
- }
-
- public EventWaiter waitEvent(final EventType event) {
- return waitEvent(new EventType[] { event } );
- }
-
- public EventWaiter waitEvent(final EventType... events) {
- EventHandler handler = new AbstractEventHandler() {
- @Override
- protected void doHandle(Event event) throws Exception {
- // no op;
- }
-
- @Override
- public EventType[] getInterestedEvents() {
- return events;
- }
- };
-
- handler.setDispatcher(this);
- final WaitEventHandler waitEventHandler = new WaitEventHandler(handler);
- register(waitEventHandler);
- EventWaiter waiter = new EventWaiter() {
- @Override
- public Event waitEvent(EventType event) {
- return waitEventHandler.waitEvent(event);
- }
-
- @Override
- public Event waitEvent() {
- return waitEventHandler.waitEvent();
- }
-
- @Override
- public Event waitEvent(EventType event, long timeout,
- TimeUnit timeUnit) throws TimeoutException {
- return waitEventHandler.waitEvent(event, timeout, timeUnit);
- }
-
- @Override
- public Event waitEvent(long timeout, TimeUnit timeUnit) throws TimeoutException {
- return waitEventHandler.waitEvent(timeout, timeUnit);
- }
- };
-
- return waiter;
- }
-
- private void process(Event event) {
- EventType eventType = event.getEventType();
- InternalEventHandler handler;
- Set<Integer> handlerIds;
-
- if (eventHandlersMap.containsKey(eventType)) {
- handlerIds = eventHandlersMap.get(eventType);
- for (Integer hid : handlerIds) {
- handler = handlers.get(hid);
- handler.handle(event);
- }
- }
-
- if (eventHandlersMap.containsKey(BuiltInEventType.ALL)) {
- handlerIds = eventHandlersMap.get(BuiltInEventType.ALL);
- for (Integer hid : handlerIds) {
- handler = handlers.get(hid);
- handler.handle(event);
- }
- }
- }
-
- public void start() {
- if (!started) {
- for (InternalEventHandler handler : handlers.values()) {
- handler.start();
- }
- started = true;
- }
- }
-
- public void stop() {
- if (started) {
- for (InternalEventHandler handler : handlers.values()) {
- handler.stop();
- }
- started = false;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/EventType.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/EventType.java b/contrib/haox-event/src/main/java/org/apache/haox/event/EventType.java
deleted file mode 100644
index 49b35bc..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/EventType.java
+++ /dev/null
@@ -1,24 +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.haox.event;
-
-public interface EventType {
- // no op
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/EventWaiter.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/EventWaiter.java b/contrib/haox-event/src/main/java/org/apache/haox/event/EventWaiter.java
deleted file mode 100644
index dc8cf22..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/EventWaiter.java
+++ /dev/null
@@ -1,35 +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.haox.event;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-public interface EventWaiter {
-
- public abstract Event waitEvent(EventType event);
-
- public abstract Event waitEvent();
-
- public abstract Event waitEvent(EventType event, long timeout, TimeUnit timeUnit) throws TimeoutException;
-
- public abstract Event waitEvent(long timeout, TimeUnit timeUnit) throws TimeoutException;
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.java
deleted file mode 100644
index c707648..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.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.haox.event;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * An EventHandler wrapper processing events using an ExecutorService
- */
-public class ExecutedEventHandler extends AbstractInternalEventHandler {
-
- private ExecutorService executorService;
-
- public ExecutedEventHandler(EventHandler handler) {
- super(handler);
- }
-
- @Override
- protected void doHandle(final Event event) throws Exception {
- if (executorService.isTerminated()) {
- return;
- }
-
- executorService.execute(new Runnable() {
- @Override
- public void run() {
- try {
- process(event);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- });
- }
-
- @Override
- public void start() {
- executorService = Executors.newFixedThreadPool(2);
- }
-
- @Override
- public void stop() {
- if (executorService.isShutdown()) {
- return;
- }
- executorService.shutdownNow();
- }
-
- @Override
- public boolean isStopped() {
- return executorService.isShutdown();
- }
-
- @Override
- public void init() {
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/InternalEventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/InternalEventHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/event/InternalEventHandler.java
deleted file mode 100644
index 799d712..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/InternalEventHandler.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.haox.event;
-
-public interface InternalEventHandler extends EventHandler {
-
- public int id();
-
- public void init();
-
- public void start();
-
- public void stop();
-
- public boolean isStopped();
-}
-
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/LongRunningEventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/LongRunningEventHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/event/LongRunningEventHandler.java
deleted file mode 100644
index dc71498..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/LongRunningEventHandler.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.haox.event;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public abstract class LongRunningEventHandler extends BufferedEventHandler {
-
- private ExecutorService executorService;
-
- public LongRunningEventHandler(EventHandler handler) {
- super(handler);
- }
-
- public LongRunningEventHandler() {
- super();
- }
-
- protected abstract void loopOnce();
-
- @Override
- public void start() {
- executorService = Executors.newFixedThreadPool(1);
- executorService.execute(new Runnable() {
- @Override
- public void run() {
- while (true) {
-
- processEvents();
-
- loopOnce();
- }
- }
- });
- }
-
- @Override
- public void stop() {
- if (executorService.isShutdown()) {
- return;
- }
- executorService.shutdownNow();
- }
-
- @Override
- public boolean isStopped() {
- return executorService.isShutdown();
- }
-
- protected void processEvents() {
- while (! eventQueue.isEmpty()) {
- try {
- process(eventQueue.take());
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/event/WaitEventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/WaitEventHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/event/WaitEventHandler.java
deleted file mode 100644
index c6d287e..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/WaitEventHandler.java
+++ /dev/null
@@ -1,128 +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.haox.event;
-
-import java.util.concurrent.*;
-
-public class WaitEventHandler extends BufferedEventHandler {
-
- private ExecutorService executorService;
-
- public WaitEventHandler(EventHandler handler) {
- super(handler);
- }
-
- public Event waitEvent() {
- return waitEvent(null);
- }
-
- public Event waitEvent(final EventType eventType) {
- Future<Event> future = doWaitEvent(eventType);
-
- try {
- return future.get();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
-
- public Event waitEvent(final EventType eventType,
- long timeout, TimeUnit timeUnit) throws TimeoutException {
- Future<Event> future = doWaitEvent(eventType);
-
- try {
- return future.get(timeout, timeUnit);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
-
- public Event waitEvent(long timeout, TimeUnit timeUnit) throws TimeoutException {
- Future<Event> future = doWaitEvent(null);
-
- try {
- return future.get(timeout, timeUnit);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
-
- private Future<Event> doWaitEvent(final EventType eventType) {
- Future<Event> future = executorService.submit(new Callable<Event>() {
- @Override
- public Event call() throws Exception {
- if (eventType != null) {
- return checkEvent(eventType);
- } else {
- return checkEvent();
- }
- }
- });
-
- return future;
- }
-
- private Event checkEvent() throws Exception {
- return eventQueue.take();
- }
-
- private Event checkEvent(EventType eventType) throws Exception {
- Event event = null;
-
- while (true) {
- if (eventQueue.size() == 1) {
- if (eventQueue.peek().getEventType() == eventType) {
- return eventQueue.take();
- }
- } else {
- event = eventQueue.take();
- if (event.getEventType() == eventType) {
- return event;
- } else {
- eventQueue.put(event); // put back since not wanted
- }
- }
- }
- }
-
- @Override
- public void start() {
- executorService = Executors.newFixedThreadPool(2);
- }
-
- @Override
- public void stop() {
- if (executorService.isShutdown()) {
- return;
- }
- executorService.shutdown();
- }
-
- @Override
- public boolean isStopped() {
- return executorService.isShutdown();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/Acceptor.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/Acceptor.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/Acceptor.java
deleted file mode 100644
index 540fe30..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/transport/Acceptor.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.haox.transport;
-
-import java.net.InetSocketAddress;
-
-public abstract class Acceptor extends TransportSelector {
-
- public Acceptor(TransportHandler transportHandler) {
- super(transportHandler);
- }
-
- public void listen(String address, short listenPort) {
- InetSocketAddress socketAddress = new InetSocketAddress(address, listenPort);
- doListen(socketAddress);
- }
-
- protected abstract void doListen(InetSocketAddress socketAddress);
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/Connector.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/Connector.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/Connector.java
deleted file mode 100644
index a021689..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/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.haox.transport;
-
-import java.net.InetSocketAddress;
-
-public abstract class Connector extends TransportSelector {
-
- public Connector(TransportHandler transportHandler) {
- super(transportHandler);
- }
-
- public void connect(String serverAddress, short serverPort) {
- InetSocketAddress sa = new InetSocketAddress(serverAddress, serverPort);
- doConnect(sa);
- }
-
- protected abstract void doConnect(InetSocketAddress sa);
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/MessageHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/MessageHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/MessageHandler.java
deleted file mode 100644
index 1d3bb41..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/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.haox.transport;
-
-import org.apache.haox.event.AbstractEventHandler;
-import org.apache.haox.event.Event;
-import org.apache.haox.event.EventType;
-import org.apache.haox.transport.event.MessageEvent;
-import org.apache.haox.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-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/Network.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/Network.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/Network.java
deleted file mode 100644
index a61925e..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/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.haox.transport;
-
-import org.apache.haox.event.AbstractEventHandler;
-import org.apache.haox.event.Event;
-import org.apache.haox.event.EventType;
-import org.apache.haox.event.LongRunningEventHandler;
-import org.apache.haox.transport.event.AddressEvent;
-import org.apache.haox.transport.event.TransportEvent;
-import org.apache.haox.transport.tcp.*;
-import org.apache.haox.transport.udp.UdpAddressEvent;
-import org.apache.haox.transport.udp.UdpEventType;
-import org.apache.haox.transport.udp.UdpTransport;
-import org.apache.haox.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, short 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, short 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, short 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, short 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) {
- // 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-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/Transport.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/Transport.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/Transport.java
deleted file mode 100644
index d4239f7..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/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.haox.transport;
-
-import org.apache.haox.event.Dispatcher;
-import org.apache.haox.transport.buffer.TransBuffer;
-import org.apache.haox.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;
-
- private int readableCount = 0;
- private 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-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/TransportHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/TransportHandler.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/TransportHandler.java
deleted file mode 100644
index fd5a7f2..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/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.haox.transport;
-
-import org.apache.haox.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-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/TransportSelector.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/TransportSelector.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/TransportSelector.java
deleted file mode 100644
index 33424a4..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/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.haox.transport;
-
-import org.apache.haox.event.Dispatcher;
-import org.apache.haox.event.LongRunningEventHandler;
-import org.apache.haox.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-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/buffer/BufferPool.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/buffer/BufferPool.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/buffer/BufferPool.java
deleted file mode 100644
index 213ec1f..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/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.haox.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-kerberos/blob/ceacb982/contrib/haox-event/src/main/java/org/apache/haox/transport/buffer/BufferUtil.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/buffer/BufferUtil.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/buffer/BufferUtil.java
deleted file mode 100644
index 292349a..0000000
--- a/contrib/haox-event/src/main/java/org/apache/haox/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.haox.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;
- }
-}