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:47:43 UTC

[04/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/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java
new file mode 100644
index 0000000..629446e
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java
@@ -0,0 +1,346 @@
+/**
+ *  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.config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+public class ConfigImpl implements Config {
+    private static final Logger logger = LoggerFactory.getLogger(Config.class);
+
+    private String resource;
+    private Map<String, ConfigObject> properties;
+    /**
+     * Config resources
+     */
+    private List<Config> configs;
+
+    private Set<String> propNames;
+
+    protected ConfigImpl(String resource) {
+        this.resource = resource;
+        this.properties = new HashMap<String, ConfigObject>();
+        this.configs = new ArrayList<Config>(0);
+    }
+
+    protected void reset() {
+        this.properties.clear();
+        this.configs.clear();
+    }
+
+    @Override
+    public String getResource() {
+        return resource;
+    }
+
+    @Override
+    public Set<String> getNames() {
+        reloadNames();
+        return propNames;
+    }
+
+    @Override
+    public String getString(String name) {
+        String result = null;
+
+        ConfigObject co = properties.get(name);
+        if (co != null) {
+            result = co.getPropertyValue();
+        }
+
+        if (result == null) {
+            for (Config config : configs) {
+                result = config.getString(name);
+                if (result != null) break;
+            }
+        }
+
+        return result;
+    }
+
+    @Override
+    public String getString(ConfigKey name) {
+        if (name.getDefaultValue() != null) {
+            return getString(name.getPropertyKey(), (String) name.getDefaultValue());
+        }
+        return getString(name.getPropertyKey());
+    }
+
+    @Override
+    public String getString(String name, String defaultValue) {
+        String result = getString(name);
+        if (result == null) {
+            result = defaultValue;
+        }
+        return result;
+    }
+
+    @Override
+    public String getTrimmed(String name) {
+        String result = getString(name);
+        if (null != result) {
+            result = result.trim();
+        }
+        return result;
+    }
+
+    @Override
+    public String getTrimmed(ConfigKey name) {
+        return getTrimmed(name.getPropertyKey());
+    }
+
+    @Override
+    public Integer getInt(String name) {
+        Integer result = null;
+        String value = getTrimmed(name);
+        if (value != null) {
+            result = Integer.valueOf(value);
+        }
+        return result;
+    }
+
+    @Override
+    public Integer getInt(ConfigKey name) {
+        if (name.getDefaultValue() != null) {
+            return getInt(name.getPropertyKey(), (Integer) name.getDefaultValue());
+        }
+        return getInt(name.getPropertyKey());
+    }
+
+    @Override
+    public Integer getInt(String name, int defaultValue) {
+        Integer result = getInt(name);
+        if (result == null) {
+            result = defaultValue;
+        }
+        return result;
+    }
+
+    @Override
+    public Long getLong(String name) {
+        Long result = null;
+        String value = getTrimmed(name);
+        if (value != null) {
+            result = Long.valueOf(value);
+        }
+        return result;
+    }
+
+    @Override
+    public Long getLong(ConfigKey name) {
+        if (name.getDefaultValue() != null) {
+            return getLong(name.getPropertyKey(), (Long) name.getDefaultValue());
+        }
+        return getLong(name.getPropertyKey());
+    }
+
+    @Override
+    public Long getLong(String name, long defaultValue) {
+        Long result = getLong(name);
+        if (result == null) {
+            result = defaultValue;
+        }
+        return result;
+    }
+
+    @Override
+    public Float getFloat(String name) {
+        Float result = null;
+        String value = getTrimmed(name);
+        if (value != null) {
+            result = Float.valueOf(value);
+        }
+        return result;
+    }
+
+    @Override
+    public Float getFloat(ConfigKey name) {
+        if (name.getDefaultValue() != null) {
+            return getFloat(name.getPropertyKey(), (Float) name.getDefaultValue());
+        }
+        return getFloat(name.getPropertyKey());
+    }
+
+    @Override
+    public Float getFloat(String name, float defaultValue) {
+        Float result = getFloat(name);
+        if (result == null) {
+            result = defaultValue;
+        }
+        return result;
+    }
+
+    @Override
+    public Boolean getBoolean(String name) {
+        Boolean result = null;
+        String value = getTrimmed(name);
+        if (value != null) {
+            result = Boolean.valueOf(value);
+        }
+        return result;
+    }
+
+    @Override
+    public Boolean getBoolean(ConfigKey name) {
+        if (name.getDefaultValue() != null) {
+            return getBoolean(name.getPropertyKey(), (Boolean) name.getDefaultValue());
+        }
+        return getBoolean(name.getPropertyKey());
+    }
+
+    @Override
+    public Boolean getBoolean(String name, boolean defaultValue) {
+        Boolean result = getBoolean(name);
+        if (result == null) {
+            result = defaultValue;
+        }
+        return result;
+    }
+
+    @Override
+    public List<String> getList(String name) {
+        List<String> results = null;
+        ConfigObject co = properties.get(name);
+        if (co != null) {
+            results = co.getListValues();
+        }
+        return results;
+    }
+
+    @Override
+    public List<String> getList(String name, String[] defaultValue) {
+        List<String> results = getList(name);
+        if (results == null) {
+            results = Arrays.asList(defaultValue);
+        }
+        return results;
+    }
+
+    @Override
+    public List<String> getList(ConfigKey name) {
+        if (name.getDefaultValue() != null) {
+            return getList(name.getPropertyKey(), (String[]) name.getDefaultValue());
+        }
+        return getList(name.getPropertyKey());
+    }
+
+    @Override
+    public Config getConfig(String name) {
+        Config result = null;
+        ConfigObject co = properties.get(name);
+        if (co != null) {
+            result = co.getConfigValue();
+        }
+        return result;
+    }
+
+    @Override
+    public Config getConfig(ConfigKey name) {
+        return getConfig(name.getPropertyKey());
+    }
+
+    @Override
+    public Class<?> getClass(String name) throws ClassNotFoundException {
+        Class<?> result = null;
+
+        String valueString = getString(name);
+        if (valueString != null) {
+            Class<?> cls = Class.forName(name);
+            result = cls;
+        }
+
+        return result;
+    }
+
+    @Override
+    public Class<?> getClass(String name, Class<?> defaultValue) throws ClassNotFoundException {
+        Class<?> result = getClass(name);
+        if (result == null) {
+            result = defaultValue;
+        }
+        return result;
+    }
+
+    @Override
+    public Class<?> getClass(ConfigKey name) throws ClassNotFoundException {
+        if (name.getDefaultValue() != null) {
+            return getClass(name.getPropertyKey(), (Class<?>) name.getDefaultValue());
+        }
+        return getClass(name.getPropertyKey());
+    }
+
+    @Override
+    public <T> T getInstance(String name) throws ClassNotFoundException {
+        return getInstance(name, null);
+    }
+
+    @Override
+    public <T> T getInstance(ConfigKey name) throws ClassNotFoundException {
+        return getInstance(name.getPropertyKey());
+    }
+
+    @Override
+    public <T> T getInstance(String name, Class<T> xface) throws ClassNotFoundException {
+        T result = null;
+
+        Class<?> cls = getClass(name, null);
+        if (xface != null && !xface.isAssignableFrom(cls)) {
+            throw new RuntimeException(cls + " does not implement " + xface);
+        }
+        try {
+            result = (T) cls.newInstance();
+        } catch (Exception e) {
+            throw new RuntimeException("Failed to create instance with class " + cls.getName());
+        }
+
+        return result;
+    }
+
+    protected void set(String name, String value) {
+        ConfigObject co = new ConfigObject(value);
+        set(name, co);
+    }
+
+    protected void set(String name, Config value) {
+        ConfigObject co = new ConfigObject(value);
+        set(name, co);
+    }
+
+    protected void set(String name, ConfigObject value) {
+        this.properties.put(name, value);
+    }
+
+    protected void add(Config config) {
+        this.configs.add(config);
+    }
+
+    private void reloadNames() {
+        if (propNames != null) {
+            propNames.clear();
+        }
+        propNames = new HashSet<String>(properties.keySet());
+        for (Config config : configs) {
+            propNames.addAll(config.getNames());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigKey.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigKey.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigKey.java
new file mode 100644
index 0000000..47f7727
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigKey.java
@@ -0,0 +1,25 @@
+/**
+ *  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.config;
+
+public interface ConfigKey {
+    public String getPropertyKey();
+    public Object getDefaultValue();
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigLoader.java
new file mode 100644
index 0000000..476ed4c
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigLoader.java
@@ -0,0 +1,50 @@
+/**
+ *  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.config;
+
+public abstract class ConfigLoader {
+    private Resource resource;
+    private ConfigImpl config;
+
+    protected void setResource(Resource resource) {
+        this.resource = resource;
+    }
+
+    protected void setConfig(ConfigImpl config) {
+        this.config = config;
+    }
+
+    public Config load() {
+        if (config == null) {
+            config = new ConfigImpl(resource.getName());
+        }
+        config.reset();
+
+        try {
+            loadConfig(config, resource);
+        } catch (Exception e) {
+            throw new RuntimeException("Failed to load org.haox.config", e);
+        }
+
+        return this.config;
+    }
+
+    protected abstract void loadConfig(ConfigImpl config, Resource resource) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java
new file mode 100644
index 0000000..c915af6
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java
@@ -0,0 +1,80 @@
+/**
+ *  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.config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ConfigObject {
+	protected static enum VALUE_TYPE { PROPERTY, LIST, CONFIG };
+		
+	private VALUE_TYPE valueType;
+	private Object value;
+	
+	public ConfigObject(String value) {
+		this.value = value;
+		this.valueType = VALUE_TYPE.PROPERTY;
+	}
+	
+	public ConfigObject(String[] values) {
+		List<String> valuesList = new ArrayList<String>();
+		for (String v : values) {
+			valuesList.add(v);
+		}
+
+		this.value = valuesList;
+		this.valueType = VALUE_TYPE.LIST;
+	}
+
+    public ConfigObject(List<String> values) {
+        this.value = new ArrayList<String>(values);
+        this.valueType = VALUE_TYPE.LIST;
+    }
+
+	public ConfigObject(Config value) {
+		this.value = value;
+		this.valueType = VALUE_TYPE.CONFIG;
+	}
+
+	public String getPropertyValue() {
+		String result = null;
+		if (valueType == VALUE_TYPE.PROPERTY) {
+			result = (String) value;
+		}
+		return result;
+	}
+	
+	public List<String> getListValues() {
+		List<String> results = null;
+		if (valueType == VALUE_TYPE.LIST) {
+            results = (List<String>) value;
+		}
+		
+		return results;
+	}
+
+	public Config getConfigValue() {
+		Config result = null;
+		if (valueType == VALUE_TYPE.CONFIG) {
+			result = (Config) value;
+		}
+		return result;
+	}
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
new file mode 100644
index 0000000..cf9f56b
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
@@ -0,0 +1,69 @@
+/**
+ *  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.config;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+public class IniConfigLoader extends ConfigLoader {
+    private static final String COMMENT_SYMBOL = "#";
+
+    private ConfigImpl rootConfig;
+    private ConfigImpl currentConfig;
+
+    /**
+     *  Load configs form the INI configuration format file.
+     */
+    @Override
+    protected void loadConfig(ConfigImpl config, Resource resource) throws IOException {
+        rootConfig = config;
+        currentConfig = config;
+
+        InputStream is = (InputStream) resource.getResource();
+        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+
+        String line;
+        while ((line = reader.readLine()) != null) {
+            parseLine(line);
+        }
+    }
+
+    private void parseLine(String line) {
+        line = line.trim();
+
+        if (line.startsWith(COMMENT_SYMBOL)) {
+            return;
+        }
+
+        if (line.matches("\\[.*\\]")) {
+            String subConfigName = line.replaceFirst("\\[(.*)\\]", "$1");
+            ConfigImpl subConfig = new ConfigImpl(subConfigName);
+            rootConfig.set(subConfigName, subConfig);
+            currentConfig = subConfig;
+        } else if (line.matches(".*=.*")) {
+            int i = line.indexOf('=');
+            String name = line.substring(0, i).trim();
+            String value = line.substring(i + 1).trim();
+            currentConfig.set(name, value);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/JsonConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/JsonConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/JsonConfigLoader.java
new file mode 100644
index 0000000..5a51175
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/JsonConfigLoader.java
@@ -0,0 +1,27 @@
+/**
+ *  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.config;
+
+public class JsonConfigLoader extends ConfigLoader {
+    @Override
+    protected void loadConfig(ConfigImpl config, Resource resource) {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
new file mode 100644
index 0000000..f83517f
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
@@ -0,0 +1,34 @@
+/**
+ *  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.config;
+
+import java.util.Map;
+
+public class MapConfigLoader extends ConfigLoader {
+    @Override
+    protected void loadConfig(ConfigImpl config, Resource resource) {
+        Map<String, String> mapConfig = (Map<String, String>) resource.getResource();
+        String value;
+        for (String key : mapConfig.keySet()) {
+            value = mapConfig.get(key);
+            config.set(key, value);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java
new file mode 100644
index 0000000..e0b9782
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java
@@ -0,0 +1,43 @@
+/**
+ *  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.config;
+
+import java.util.Properties;
+
+public class PropertiesConfigLoader extends ConfigLoader {
+
+    @Override
+    protected void loadConfig(ConfigImpl config, Resource resource) throws Exception {
+        Properties propConfig = (Properties) resource.getResource();
+        loadConfig(config, propConfig);
+    }
+
+    protected void loadConfig(ConfigImpl config, Properties propConfig) {
+        Object value;
+        for (Object key : propConfig.keySet()) {
+            if (key instanceof String) {
+                value = propConfig.getProperty((String) key);
+                if (value != null && value instanceof String) {
+                    config.set((String) key, (String) value);
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesFileConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesFileConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesFileConfigLoader.java
new file mode 100644
index 0000000..ba8660f
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesFileConfigLoader.java
@@ -0,0 +1,33 @@
+/**
+ *  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.config;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+public class PropertiesFileConfigLoader extends PropertiesConfigLoader {
+
+    @Override
+    protected void loadConfig(ConfigImpl config, Resource resource) throws Exception {
+        Properties propConfig = new Properties();
+        propConfig.load((InputStream) resource.getResource());
+        loadConfig(config, propConfig);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-config/src/main/java/org/apache/kerby/config/Resource.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/Resource.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/Resource.java
new file mode 100644
index 0000000..9da0405
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/Resource.java
@@ -0,0 +1,119 @@
+/**
+ *  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.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/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java
new file mode 100644
index 0000000..2208abc
--- /dev/null
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java
@@ -0,0 +1,159 @@
+/**
+ *  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.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/lib/kerby-config/src/test/java/org/apache/kerby/config/ConfTest.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/test/java/org/apache/kerby/config/ConfTest.java b/lib/kerby-config/src/test/java/org/apache/kerby/config/ConfTest.java
new file mode 100644
index 0000000..9a7ffdb
--- /dev/null
+++ b/lib/kerby-config/src/test/java/org/apache/kerby/config/ConfTest.java
@@ -0,0 +1,133 @@
+/**
+ *  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.config;
+
+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/lib/kerby-config/src/test/java/org/apache/kerby/config/ConfigImplTest.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/test/java/org/apache/kerby/config/ConfigImplTest.java b/lib/kerby-config/src/test/java/org/apache/kerby/config/ConfigImplTest.java
new file mode 100644
index 0000000..1834a9f
--- /dev/null
+++ b/lib/kerby-config/src/test/java/org/apache/kerby/config/ConfigImplTest.java
@@ -0,0 +1,62 @@
+/**
+ *  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.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/lib/kerby-config/src/test/java/org/apache/kerby/config/IniConfigTest.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/test/java/org/apache/kerby/config/IniConfigTest.java b/lib/kerby-config/src/test/java/org/apache/kerby/config/IniConfigTest.java
new file mode 100644
index 0000000..f71e5a1
--- /dev/null
+++ b/lib/kerby-config/src/test/java/org/apache/kerby/config/IniConfigTest.java
@@ -0,0 +1,76 @@
+/**
+ *  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.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/lib/kerby-event/README
----------------------------------------------------------------------
diff --git a/lib/kerby-event/README b/lib/kerby-event/README
new file mode 100644
index 0000000..cb3b88a
--- /dev/null
+++ b/lib/kerby-event/README
@@ -0,0 +1 @@
+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/lib/kerby-event/pom.xml
----------------------------------------------------------------------
diff --git a/lib/kerby-event/pom.xml b/lib/kerby-event/pom.xml
new file mode 100644
index 0000000..af1e11a
--- /dev/null
+++ b/lib/kerby-event/pom.xml
@@ -0,0 +1,28 @@
+<?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>lib</artifactId>
+    <groupId>org.apache.kerby</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>kerby-event</artifactId>
+  <name>Kerby Event</name>
+  <description>Kerby Event and Transport facilities for both client and server</description>
+
+</project>

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-event/src/main/java/org/apache/kerby/event/AbstractEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/AbstractEventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/AbstractEventHandler.java
new file mode 100644
index 0000000..59a0a82
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/AbstractEventHandler.java
@@ -0,0 +1,55 @@
+/**
+ *  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;
+
+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/lib/kerby-event/src/main/java/org/apache/kerby/event/AbstractInternalEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/AbstractInternalEventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/AbstractInternalEventHandler.java
new file mode 100644
index 0000000..bfed126
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/AbstractInternalEventHandler.java
@@ -0,0 +1,66 @@
+/**
+ *  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.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/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java
new file mode 100644
index 0000000..39fca9f
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java
@@ -0,0 +1,53 @@
+/**
+ *  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.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/lib/kerby-event/src/main/java/org/apache/kerby/event/Dispatcher.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/Dispatcher.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/Dispatcher.java
new file mode 100644
index 0000000..f5a9f53
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/Dispatcher.java
@@ -0,0 +1,29 @@
+/**
+ *  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;
+
+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/lib/kerby-event/src/main/java/org/apache/kerby/event/Event.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/Event.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/Event.java
new file mode 100644
index 0000000..332ee0d
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/Event.java
@@ -0,0 +1,43 @@
+/**
+ *  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;
+
+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/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHandler.java
new file mode 100644
index 0000000..b9ef871
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHandler.java
@@ -0,0 +1,31 @@
+/**
+ *  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;
+
+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/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java
new file mode 100644
index 0000000..931455a
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java
@@ -0,0 +1,192 @@
+/**
+ *  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.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/lib/kerby-event/src/main/java/org/apache/kerby/event/EventType.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/EventType.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventType.java
new file mode 100644
index 0000000..6a4a453
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventType.java
@@ -0,0 +1,24 @@
+/**
+ *  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;
+
+public interface EventType {
+    // no op
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ceacb982/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java
new file mode 100644
index 0000000..5e6d7b1
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java
@@ -0,0 +1,35 @@
+/**
+ *  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.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/lib/kerby-event/src/main/java/org/apache/kerby/event/ExecutedEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/ExecutedEventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/ExecutedEventHandler.java
new file mode 100644
index 0000000..d094711
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/ExecutedEventHandler.java
@@ -0,0 +1,76 @@
+/**
+ *  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.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/lib/kerby-event/src/main/java/org/apache/kerby/event/InternalEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/InternalEventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/InternalEventHandler.java
new file mode 100644
index 0000000..6adff3c
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/InternalEventHandler.java
@@ -0,0 +1,34 @@
+/**
+ *  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;
+
+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/lib/kerby-event/src/main/java/org/apache/kerby/event/LongRunningEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/LongRunningEventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/LongRunningEventHandler.java
new file mode 100644
index 0000000..10c1f0b
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/LongRunningEventHandler.java
@@ -0,0 +1,77 @@
+/**
+ *  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.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/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java
new file mode 100644
index 0000000..9edc230
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java
@@ -0,0 +1,128 @@
+/**
+ *  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.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/lib/kerby-event/src/main/java/org/apache/kerby/transport/Acceptor.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/Acceptor.java b/lib/kerby-event/src/main/java/org/apache/kerby/transport/Acceptor.java
new file mode 100644
index 0000000..8fa25d7
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/transport/Acceptor.java
@@ -0,0 +1,36 @@
+/**
+ *  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 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/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
new file mode 100644
index 0000000..ece171f
--- /dev/null
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/transport/Connector.java
@@ -0,0 +1,36 @@
+/**
+ *  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, short serverPort) {
+        InetSocketAddress sa = new InetSocketAddress(serverAddress, serverPort);
+        doConnect(sa);
+    }
+
+    protected abstract void doConnect(InetSocketAddress sa);
+}