zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject [42/51] [partial] zookeeper git commit: ZOOKEEPER-3032: MAVEN MIGRATION - branch 3.4 move java server, client
Date Wed, 10 Oct 2018 10:30:41 GMT
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/common/PathTrie.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/common/PathTrie.java b/src/java/main/org/apache/zookeeper/common/PathTrie.java
deleted file mode 100644
index 73053e0..0000000
--- a/src/java/main/org/apache/zookeeper/common/PathTrie.java
+++ /dev/null
@@ -1,293 +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.zookeeper.common;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * a class that implements prefix matching for 
- * components of a filesystem path. the trie
- * looks like a tree with edges mapping to 
- * the component of a path.
- * example /ab/bc/cf would map to a trie
- *           /
- *        ab/
- *        (ab)
- *      bc/
- *       / 
- *      (bc)
- *   cf/
- *   (cf)
- */    
-public class PathTrie {
-    /**
-     * the logger for this class
-     */
-    private static final Logger LOG = LoggerFactory.getLogger(PathTrie.class);
-    
-    /**
-     * the root node of PathTrie
-     */
-    private final TrieNode rootNode ;
-    
-    static class TrieNode {
-        boolean property = false;
-        final HashMap<String, TrieNode> children;
-        TrieNode parent = null;
-        /**
-         * create a trienode with parent
-         * as parameter
-         * @param parent the parent of this trienode
-         */
-        private TrieNode(TrieNode parent) {
-            children = new HashMap<String, TrieNode>();
-            this.parent = parent;
-        }
-        
-        /**
-         * get the parent of this node
-         * @return the parent node
-         */
-        TrieNode getParent() {
-            return this.parent;
-        }
-        
-        /**
-         * set the parent of this node
-         * @param parent the parent to set to
-         */
-        void setParent(TrieNode parent) {
-            this.parent = parent;
-        }
-        
-        /**
-         * a property that is set 
-         * for a node - making it 
-         * special.
-         */
-        void setProperty(boolean prop) {
-            this.property = prop;
-        }
-        
-        /** the property of this
-         * node 
-         * @return the property for this
-         * node
-         */
-        boolean getProperty() {
-            return this.property;
-        }
-        /**
-         * add a child to the existing node
-         * @param childName the string name of the child
-         * @param node the node that is the child
-         */
-        void addChild(String childName, TrieNode node) {
-            synchronized(children) {
-                if (children.containsKey(childName)) {
-                    return;
-                }
-                children.put(childName, node);
-            }
-        }
-     
-        /**
-         * delete child from this node
-         * @param childName the string name of the child to 
-         * be deleted
-         */
-        void deleteChild(String childName) {
-            synchronized(children) {
-                if (!children.containsKey(childName)) {
-                    return;
-                }
-                TrieNode childNode = children.get(childName);
-                // this is the only child node.
-                if (childNode.getChildren().length == 1) { 
-                    childNode.setParent(null);
-                    children.remove(childName);
-                }
-                else {
-                    // their are more child nodes
-                    // so just reset property.
-                    childNode.setProperty(false);
-                }
-            }
-        }
-        
-        /**
-         * return the child of a node mapping
-         * to the input childname
-         * @param childName the name of the child
-         * @return the child of a node
-         */
-        TrieNode getChild(String childName) {
-            synchronized(children) {
-               if (!children.containsKey(childName)) {
-                   return null;
-               }
-               else {
-                   return children.get(childName);
-               }
-            }
-        }
-
-        /**
-         * get the list of children of this 
-         * trienode.
-         * @param node to get its children
-         * @return the string list of its children
-         */
-        String[] getChildren() {
-           synchronized(children) {
-               return children.keySet().toArray(new String[0]);
-           }
-        }
-        
-        /**
-         * get the string representation
-         * for this node
-         */
-        public String toString() {
-            StringBuilder sb = new StringBuilder();
-            sb.append("Children of trienode: ");
-            synchronized(children) {
-                for (String str: children.keySet()) {
-                    sb.append(" " + str);
-                }
-            }
-            return sb.toString();
-        }
-    }
-    
-    /**
-     * construct a new PathTrie with
-     * a root node of /
-     */
-    public PathTrie() {
-        this.rootNode = new TrieNode(null);
-    }
-    
-    /**
-     * add a path to the path trie 
-     * @param path
-     */
-    public void addPath(String path) {
-        if (path == null) {
-            return;
-        }
-        String[] pathComponents = path.split("/");
-        TrieNode parent = rootNode;
-        String part = null;
-        if (pathComponents.length <= 1) {
-            throw new IllegalArgumentException("Invalid path " + path);
-        }
-        for (int i=1; i<pathComponents.length; i++) {
-            part = pathComponents[i];
-            if (parent.getChild(part) == null) {
-                parent.addChild(part, new TrieNode(parent));
-            }
-            parent = parent.getChild(part);
-        }
-        parent.setProperty(true);
-    }
-    
-    /**
-     * delete a path from the trie
-     * @param path the path to be deleted
-     */
-    public void deletePath(String path) {
-        if (path == null) {
-            return;
-        }
-        String[] pathComponents = path.split("/");
-        TrieNode parent = rootNode;
-        String part = null;
-        if (pathComponents.length <= 1) { 
-            throw new IllegalArgumentException("Invalid path " + path);
-        }
-        for (int i=1; i<pathComponents.length; i++) {
-            part = pathComponents[i];
-            if (parent.getChild(part) == null) {
-                //the path does not exist 
-                return;
-            }
-            parent = parent.getChild(part);
-            LOG.info("{}",parent);
-        }
-        TrieNode realParent  = parent.getParent();
-        realParent.deleteChild(part);
-    }
-    
-    /**
-     * return the largest prefix for the input path.
-     * @param path the input path
-     * @return the largest prefix for the input path.
-     */
-    public String findMaxPrefix(String path) {
-        if (path == null) {
-            return null;
-        }
-        if ("/".equals(path)) {
-            return path;
-        }
-        String[] pathComponents = path.split("/");
-        TrieNode parent = rootNode;
-        List<String> components = new ArrayList<String>();
-        if (pathComponents.length <= 1) {
-            throw new IllegalArgumentException("Invalid path " + path);
-        }
-        int i = 1;
-        String part = null;
-        StringBuilder sb = new StringBuilder();
-        int lastindex = -1;
-        while((i < pathComponents.length)) {
-            if (parent.getChild(pathComponents[i]) != null) {
-                part = pathComponents[i];
-                parent = parent.getChild(part);
-                components.add(part);
-                if (parent.getProperty()) {
-                    lastindex = i-1;
-                }
-            }
-            else {
-                break;
-            }
-            i++;
-        }
-        for (int j=0; j< (lastindex+1); j++) {
-            sb.append("/" + components.get(j));
-        }
-        return sb.toString();
-    }
-
-    /**
-     * clear all nodes
-     */
-    public void clear() {
-        for(String child : rootNode.getChildren()) {
-            rootNode.deleteChild(child);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/common/PathUtils.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/common/PathUtils.java b/src/java/main/org/apache/zookeeper/common/PathUtils.java
deleted file mode 100644
index 2a6c7ef..0000000
--- a/src/java/main/org/apache/zookeeper/common/PathUtils.java
+++ /dev/null
@@ -1,103 +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.zookeeper.common;
-
-
-/**
- * Path related utilities
- */    
-public class PathUtils {
-	
-	/** validate the provided znode path string
-	 * @param path znode path string
-	 * @param isSequential if the path is being created
-	 * with a sequential flag
-	 * @throws IllegalArgumentException if the path is invalid
-	 */
-	public static void validatePath(String path, boolean isSequential) 
-		throws IllegalArgumentException {
-		validatePath(isSequential? path + "1": path);
-	}
-	
-    /**
-     * Validate the provided znode path string
-     * @param path znode path string
-     * @throws IllegalArgumentException if the path is invalid
-     */
-    public static void validatePath(String path) throws IllegalArgumentException {
-        if (path == null) {
-            throw new IllegalArgumentException("Path cannot be null");
-        }
-        if (path.length() == 0) {
-            throw new IllegalArgumentException("Path length must be > 0");
-        }
-        if (path.charAt(0) != '/') {
-            throw new IllegalArgumentException(
-                         "Path must start with / character");
-        }
-        if (path.length() == 1) { // done checking - it's the root
-            return;
-        }
-        if (path.charAt(path.length() - 1) == '/') {
-            throw new IllegalArgumentException(
-                         "Path must not end with / character");
-        }
-
-        String reason = null;
-        char lastc = '/';
-        char chars[] = path.toCharArray();
-        char c;
-        for (int i = 1; i < chars.length; lastc = chars[i], i++) {
-            c = chars[i];
-
-            if (c == 0) {
-                reason = "null character not allowed @" + i;
-                break;
-            } else if (c == '/' && lastc == '/') {
-                reason = "empty node name specified @" + i;
-                break;
-            } else if (c == '.' && lastc == '.') {
-                if (chars[i-2] == '/' &&
-                        ((i + 1 == chars.length)
-                                || chars[i+1] == '/')) {
-                    reason = "relative paths not allowed @" + i;
-                    break;
-                }
-            } else if (c == '.') {
-                if (chars[i-1] == '/' &&
-                        ((i + 1 == chars.length)
-                                || chars[i+1] == '/')) {
-                    reason = "relative paths not allowed @" + i;
-                    break;
-                }
-            } else if (c > '\u0000' && c < '\u001f'
-                    || c > '\u007f' && c < '\u009F'
-                    || c > '\ud800' && c < '\uf8ff'
-                    || c > '\ufff0' && c < '\uffff') {
-                reason = "invalid character @" + i;
-                break;
-            }
-        }
-
-        if (reason != null) {
-            throw new IllegalArgumentException(
-                    "Invalid path string \"" + path + "\" caused by " + reason);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/common/Time.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/common/Time.java b/src/java/main/org/apache/zookeeper/common/Time.java
deleted file mode 100644
index 83e53f0..0000000
--- a/src/java/main/org/apache/zookeeper/common/Time.java
+++ /dev/null
@@ -1,52 +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.zookeeper.common;
-
-import java.util.Date;
-
-public class Time {
-    /**
-     * Returns time in milliseconds as does System.currentTimeMillis(),
-     * but uses elapsed time from an arbitrary epoch more like System.nanoTime().
-     * The difference is that if somebody changes the system clock,
-     * Time.currentElapsedTime will change but nanoTime won't. On the other hand,
-     * all of ZK assumes that time is measured in milliseconds.
-     * @return  The time in milliseconds from some arbitrary point in time.
-     */
-    public static long currentElapsedTime() {
-        return System.nanoTime() / 1000000;
-    }
-
-    /**
-     * Explicitly returns system dependent current wall time.
-     * @return Current time in msec.
-     */
-    public static long currentWallTime() {
-        return System.currentTimeMillis();
-    }
-
-    /**
-     * This is to convert the elapsedTime to a Date.
-     * @return A date object indicated by the elapsedTime.
-     */
-    public static Date elapsedTimeToDate(long elapsedTime) {
-        long wallTime = currentWallTime() + elapsedTime - currentElapsedTime();
-        return new Date(wallTime);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/jmx/CommonNames.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/jmx/CommonNames.java b/src/java/main/org/apache/zookeeper/jmx/CommonNames.java
deleted file mode 100644
index 986d69d..0000000
--- a/src/java/main/org/apache/zookeeper/jmx/CommonNames.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.zookeeper.jmx;
-
-/**
- * A bunch of constants.
- * TODO: will get rid of it eventually.
- */
-public class CommonNames {
-    public static final String DOMAIN="org.apache.ZooKeeperService";
-    public static final String DATA_TREE_KEY="DataTree";
-    public static final String STANDALONE_SERVER_KEY="StandaloneServer";
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java b/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
deleted file mode 100644
index 0fcfe2f..0000000
--- a/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
+++ /dev/null
@@ -1,219 +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.zookeeper.jmx;
-
-import java.lang.management.ManagementFactory;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class provides a unified interface for registering/unregistering of
- * zookeeper MBeans with the platform MBean server. It builds a hierarchy of MBeans
- * where each MBean represented by a filesystem-like path. Eventually, this hierarchy
- * will be stored in the zookeeper data tree instance as a virtual data tree.
- */
-public class MBeanRegistry {
-    private static final Logger LOG = LoggerFactory.getLogger(MBeanRegistry.class);
-    
-    private static volatile MBeanRegistry instance = new MBeanRegistry();
-    
-    private Map<ZKMBeanInfo, String> mapBean2Path =
-        new ConcurrentHashMap<ZKMBeanInfo, String>();
-    
-    private Map<String, ZKMBeanInfo> mapName2Bean =
-        new ConcurrentHashMap<String, ZKMBeanInfo>();
-
-    private MBeanServer mBeanServer;
-
-    public static void setInstance(MBeanRegistry instance) {
-        MBeanRegistry.instance = instance;
-    }
-
-    public static MBeanRegistry getInstance() {
-        return instance;
-    }
-
-    public MBeanRegistry () {
-        try {
-            mBeanServer = ManagementFactory.getPlatformMBeanServer();        
-        } catch (Error e) {
-            // Account for running within IKVM and create a new MBeanServer
-            // if the PlatformMBeanServer does not exist.
-            mBeanServer =  MBeanServerFactory.createMBeanServer();
-        }
-    }
-
-    /**
-     * Return the underlying MBeanServer that is being
-     * used to register MBean's. The returned MBeanServer
-     * may be a new empty MBeanServer if running through IKVM.
-     */
-    public MBeanServer getPlatformMBeanServer() {
-        return mBeanServer;
-    }
-
-    /**
-     * Registers a new MBean with the platform MBean server. 
-     * @param bean the bean being registered
-     * @param parent if not null, the new bean will be registered as a child
-     * node of this parent.
-     */
-    public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
-        throws JMException
-    {
-        assert bean != null;
-        String path = null;
-        if (parent != null) {
-            path = mapBean2Path.get(parent);
-            assert path != null;
-        }
-        path = makeFullPath(path, parent);
-        if(bean.isHidden())
-            return;
-        ObjectName oname = makeObjectName(path, bean);
-        try {
-            mBeanServer.registerMBean(bean, oname);
-            mapBean2Path.put(bean, path);
-            mapName2Bean.put(bean.getName(), bean);
-        } catch (JMException e) {
-            LOG.warn("Failed to register MBean " + bean.getName());
-            throw e;
-        }
-    }
-
-    /**
-     * Unregister the MBean identified by the path.
-     * @param path
-     * @param bean
-     */
-    private void unregister(String path,ZKMBeanInfo bean) throws JMException {
-        if(path==null)
-            return;
-        if (!bean.isHidden()) {
-            try {
-                mBeanServer.unregisterMBean(makeObjectName(path, bean));
-            } catch (JMException e) {
-                LOG.warn("Failed to unregister MBean " + bean.getName());
-                throw e;
-            }
-        }        
-    }
-    
-    /**
-     * Unregister MBean.
-     * @param bean
-     */
-    public void unregister(ZKMBeanInfo bean) {
-        if(bean==null)
-            return;
-        String path=mapBean2Path.get(bean);
-        try {
-            unregister(path,bean);
-        } catch (JMException e) {
-            LOG.warn("Error during unregister", e);
-        }
-        mapBean2Path.remove(bean);
-        mapName2Bean.remove(bean.getName());
-    }
-    /**
-     * Unregister all currently registered MBeans
-     */
-    public void unregisterAll() {
-        for(Map.Entry<ZKMBeanInfo,String> e: mapBean2Path.entrySet()) {
-            try {
-                unregister(e.getValue(), e.getKey());
-            } catch (JMException e1) {
-                LOG.warn("Error during unregister", e1);
-            }
-        }
-        mapBean2Path.clear();
-        mapName2Bean.clear();
-    }
-    /**
-     * Generate a filesystem-like path.
-     * @param prefix path prefix
-     * @param name path elements
-     * @return absolute path
-     */
-    public String makeFullPath(String prefix, String... name) {
-        StringBuilder sb=new StringBuilder(prefix == null ? "/" : (prefix.equals("/")?prefix:prefix+"/"));
-        boolean first=true;
-        for (String s : name) {
-            if(s==null) continue;
-            if(!first){
-                sb.append("/");
-            }else
-                first=false;
-            sb.append(s);
-        }
-        return sb.toString();
-    }
-    
-    protected String makeFullPath(String prefix, ZKMBeanInfo bean) {
-        return makeFullPath(prefix, bean == null ? null : bean.getName());
-    }
-
-    /**
-     * This takes a path, such as /a/b/c, and converts it to 
-     * name0=a,name1=b,name2=c
-     */
-    private int tokenize(StringBuilder sb, String path, int index){
-        String[] tokens = path.split("/");
-        for (String s: tokens) {
-            if (s.length()==0)
-                continue;
-            sb.append("name").append(index++)
-                    .append("=").append(s).append(",");
-        }
-        return index;
-    }
-    /**
-     * Builds an MBean path and creates an ObjectName instance using the path. 
-     * @param path MBean path
-     * @param bean the MBean instance
-     * @return ObjectName to be registered with the platform MBean server
-     */
-    protected ObjectName makeObjectName(String path, ZKMBeanInfo bean)
-        throws MalformedObjectNameException
-    {
-        if(path==null)
-            return null;
-        StringBuilder beanName = new StringBuilder(CommonNames.DOMAIN + ":");
-        int counter=0;
-        counter=tokenize(beanName,path,counter);
-        tokenize(beanName,bean.getName(),counter);
-        beanName.deleteCharAt(beanName.length()-1);
-        try {
-            return new ObjectName(beanName.toString());
-        } catch (MalformedObjectNameException e) {
-            LOG.warn("Invalid name \"" + beanName.toString() + "\" for class "
-                    + bean.getClass().toString());
-            throw e;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java b/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java
deleted file mode 100644
index 2f04281..0000000
--- a/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java
+++ /dev/null
@@ -1,72 +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.zookeeper.jmx;
-
-import java.util.Enumeration;
-
-import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.jmx.HierarchyDynamicMBean;
-import org.apache.log4j.spi.LoggerRepository;
-
-/**
- * Shared utilities
- */
-public class ManagedUtil {
-    /**
-     * Register the log4j JMX mbeans. Set environment variable
-     * "zookeeper.jmx.log4j.disable" to true to disable registration.
-     * @see http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/jmx/package-summary.html
-     * @throws JMException if registration fails
-     */
-    @SuppressWarnings("rawtypes")
-    public static void registerLog4jMBeans() throws JMException {
-        if (Boolean.getBoolean("zookeeper.jmx.log4j.disable") == true) {
-            return;
-        }
-        
-        MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer();
-
-        // Create and Register the top level Log4J MBean
-        HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
-
-        ObjectName mbo = new ObjectName("log4j:hiearchy=default");
-        mbs.registerMBean(hdm, mbo);
-
-        // Add the root logger to the Hierarchy MBean
-        Logger rootLogger = Logger.getRootLogger();
-        hdm.addLoggerMBean(rootLogger.getName());
-
-        // Get each logger from the Log4J Repository and add it to
-        // the Hierarchy MBean created above.
-        LoggerRepository r = LogManager.getLoggerRepository();
-        Enumeration enumer = r.getCurrentLoggers();
-        Logger logger = null;
-
-        while (enumer.hasMoreElements()) {
-           logger = (Logger) enumer.nextElement();
-           hdm.addLoggerMBean(logger.getName());
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java b/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java
deleted file mode 100644
index 1e87d92..0000000
--- a/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.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.zookeeper.jmx;
-
-/**
- * Zookeeper MBean info interface. MBeanRegistry uses the interface to generate
- * JMX object name.
- */
-public interface ZKMBeanInfo {
-    /**
-     * @return a string identifying the MBean 
-     */
-    public String getName();
-    /**
-     * If isHidden returns true, the MBean won't be registered with MBean server,
-     * and thus won't be available for management tools. Used for grouping MBeans.
-     * @return true if the MBean is hidden.
-     */
-    public boolean isHidden();
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/server/ByteBufferInputStream.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ByteBufferInputStream.java b/src/java/main/org/apache/zookeeper/server/ByteBufferInputStream.java
deleted file mode 100644
index e5ac120..0000000
--- a/src/java/main/org/apache/zookeeper/server/ByteBufferInputStream.java
+++ /dev/null
@@ -1,82 +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.zookeeper.server;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-
-import org.apache.jute.BinaryInputArchive;
-import org.apache.jute.Record;
-
-public class ByteBufferInputStream extends InputStream {
-    ByteBuffer bb;
-
-    public ByteBufferInputStream(ByteBuffer bb) {
-        this.bb = bb;
-    }
-
-    @Override
-    public int read() throws IOException {
-        if (bb.remaining() == 0) {
-            return -1;
-        }
-        return bb.get() & 0xff;
-    }
-
-    @Override
-    public int available() throws IOException {
-        return bb.remaining();
-    }
-
-    @Override
-    public int read(byte[] b, int off, int len) throws IOException {
-        if (bb.remaining() == 0) {
-            return -1;
-        }
-        if (len > bb.remaining()) {
-            len = bb.remaining();
-        }
-        bb.get(b, off, len);
-        return len;
-    }
-
-    @Override
-    public int read(byte[] b) throws IOException {
-        return read(b, 0, b.length);
-    }
-
-    @Override
-    public long skip(long n) throws IOException {
-        long newPos = bb.position() + n;
-        if (newPos > bb.remaining()) {
-            n = bb.remaining();
-        }
-        bb.position(bb.position() + (int) n);
-        return n;
-    }
-
-    static public void byteBuffer2Record(ByteBuffer bb, Record record)
-            throws IOException {
-        BinaryInputArchive ia;
-        ia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb));
-        record.deserialize(ia, "request");
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/server/ByteBufferOutputStream.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ByteBufferOutputStream.java b/src/java/main/org/apache/zookeeper/server/ByteBufferOutputStream.java
deleted file mode 100644
index a2fcc95..0000000
--- a/src/java/main/org/apache/zookeeper/server/ByteBufferOutputStream.java
+++ /dev/null
@@ -1,52 +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.zookeeper.server;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-
-import org.apache.jute.BinaryInputArchive;
-import org.apache.jute.BinaryOutputArchive;
-import org.apache.jute.Record;
-
-public class ByteBufferOutputStream extends OutputStream {
-    ByteBuffer bb;
-    public ByteBufferOutputStream(ByteBuffer bb) {
-        this.bb = bb;
-    }
-    @Override
-    public void write(int b) throws IOException {
-        bb.put((byte)b);
-    }
-    @Override
-    public void write(byte[] b) throws IOException {
-        bb.put(b);
-    }
-    @Override
-    public void write(byte[] b, int off, int len) throws IOException {
-        bb.put(b, off, len);
-    }
-    static public void record2ByteBuffer(Record record, ByteBuffer bb)
-    throws IOException {
-        BinaryOutputArchive oa;
-        oa = BinaryOutputArchive.getArchive(new ByteBufferOutputStream(bb));
-        record.serialize(oa, "request");
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/server/ConnectionBean.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ConnectionBean.java b/src/java/main/org/apache/zookeeper/server/ConnectionBean.java
deleted file mode 100644
index 58917e0..0000000
--- a/src/java/main/org/apache/zookeeper/server/ConnectionBean.java
+++ /dev/null
@@ -1,173 +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.zookeeper.server;
-
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.util.Arrays;
-
-import javax.management.ObjectName;
-
-import org.apache.zookeeper.common.Time;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.jmx.MBeanRegistry;
-import org.apache.zookeeper.jmx.ZKMBeanInfo;
-
-/**
- * Implementation of connection MBean interface.
- */
-public class ConnectionBean implements ConnectionMXBean, ZKMBeanInfo {
-    private static final Logger LOG = LoggerFactory.getLogger(ConnectionBean.class);
-
-    private final ServerCnxn connection;
-    private final Stats stats;
-
-    private final ZooKeeperServer zk;
-    
-    private final String remoteIP;
-    private final long sessionId;
-
-    public ConnectionBean(ServerCnxn connection,ZooKeeperServer zk){
-        this.connection = connection;
-        this.stats = connection;
-        this.zk = zk;
-        
-        InetSocketAddress sockAddr = connection.getRemoteSocketAddress();
-        if (sockAddr == null) {
-            remoteIP = "Unknown";
-        } else {
-            InetAddress addr = sockAddr.getAddress();
-            if (addr instanceof Inet6Address) {
-                remoteIP = ObjectName.quote(addr.getHostAddress());
-            } else {
-                remoteIP = addr.getHostAddress();
-            }
-        }
-        sessionId = connection.getSessionId();
-    }
-    
-    public String getSessionId() {
-        return "0x" + Long.toHexString(sessionId);
-    }
-
-    public String getSourceIP() {
-        InetSocketAddress sockAddr = connection.getRemoteSocketAddress();
-        if (sockAddr == null) {
-            return null;
-        }
-        return sockAddr.getAddress().getHostAddress()
-            + ":" + sockAddr.getPort();
-    }
-
-    public String getName() {
-        return MBeanRegistry.getInstance().makeFullPath("Connections", remoteIP,
-                getSessionId());
-    }
-    
-    public boolean isHidden() {
-        return false;
-    }
-    
-    public String[] getEphemeralNodes() {
-        if(zk.getZKDatabase()  !=null){
-            String[] res = zk.getZKDatabase().getEphemerals(sessionId)
-                .toArray(new String[0]);
-            Arrays.sort(res);
-            return res;
-        }
-        return null;
-    }
-    
-    public String getStartedTime() {
-        return stats.getEstablished().toString();
-    }
-    
-    public void terminateSession() {
-        try {
-            zk.closeSession(sessionId);
-        } catch (Exception e) {
-            LOG.warn("Unable to closeSession() for session: 0x" 
-                    + getSessionId(), e);
-        }
-    }
-    
-    public void terminateConnection() {
-        connection.sendCloseSession();
-    }
-
-    public void resetCounters() {
-        stats.resetStats();
-    }
-
-    @Override
-    public String toString() {
-        return "ConnectionBean{ClientIP=" + ObjectName.quote(getSourceIP())
-            + ",SessionId=0x" + getSessionId() + "}";
-    }
-    
-    public long getOutstandingRequests() {
-        return stats.getOutstandingRequests();
-    }
-    
-    public long getPacketsReceived() {
-        return stats.getPacketsReceived();
-    }
-    
-    public long getPacketsSent() {
-        return stats.getPacketsSent();
-    }
-    
-    public int getSessionTimeout() {
-        return connection.getSessionTimeout();
-    }
-
-    public long getMinLatency() {
-        return stats.getMinLatency();
-    }
-
-    public long getAvgLatency() {
-        return stats.getAvgLatency();
-    }
-
-    public long getMaxLatency() {
-        return stats.getMaxLatency();
-    }
-    
-    public String getLastOperation() {
-        return stats.getLastOperation();
-    }
-
-    public String getLastCxid() {
-        return "0x" + Long.toHexString(stats.getLastCxid());
-    }
-
-    public String getLastZxid() {
-        return "0x" + Long.toHexString(stats.getLastZxid());
-    }
-
-    public String getLastResponseTime() {
-        return Time.elapsedTimeToDate(stats.getLastResponseTime()).toString();
-    }
-
-    public long getLastLatency() {
-        return stats.getLastLatency();
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java b/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java
deleted file mode 100644
index 8bdec9a..0000000
--- a/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java
+++ /dev/null
@@ -1,98 +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.zookeeper.server;
-
-/**
- * This MBean represents a client connection.
- */
-public interface ConnectionMXBean {
-    /**
-     * @return source (client) IP address
-     */
-    public String getSourceIP();
-    /**
-     * @return client's session id
-     */
-    public String getSessionId();
-    /**
-     * @return time the connection was started
-     */
-    public String getStartedTime();
-    /**
-     * @return number of ephemeral nodes owned by this connection
-     */
-    public String[] getEphemeralNodes();
-    /**
-     * @return packets received from this client
-     */
-    public long getPacketsReceived();
-    /**
-     * @return number of packets sent to this client
-     */
-    public long getPacketsSent();
-    /**
-     * @return number of requets being processed
-     */
-    public long getOutstandingRequests();
-    /**
-     * @return session timeout in ms
-     */
-    public int getSessionTimeout();
-    
-    /**
-     * Terminate this client session. The client will reconnect with a different
-     * session id.
-     */
-    public void terminateSession();
-    /**
-     * Terminate thei client connection. The client will immediately attempt to 
-     * reconnect with the same session id.
-     */
-    public void terminateConnection();
-
-
-    /** Min latency in ms
-     * @since 3.3.0 */
-    long getMinLatency();
-    /** Average latency in ms
-     * @since 3.3.0 */
-    long getAvgLatency();
-    /** Max latency in ms
-     * @since 3.3.0 */
-    long getMaxLatency();
-    /** Last operation performed by this connection
-     * @since 3.3.0 */
-    String getLastOperation();
-    /** Last cxid of this connection
-     * @since 3.3.0 */
-    String getLastCxid();
-    /** Last zxid of this connection
-     * @since 3.3.0 */
-    String getLastZxid();
-    /** Last time server sent a response to client on this connection
-     * @since 3.3.0 */
-    String getLastResponseTime();
-    /** Latency of last response to client on this connection in ms
-     * @since 3.3.0 */
-    long getLastLatency();
-
-    /** Reset counters
-     * @since 3.3.0 */
-    void resetCounters();
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/c0aa3b3f/src/java/main/org/apache/zookeeper/server/DataNode.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/DataNode.java b/src/java/main/org/apache/zookeeper/server/DataNode.java
deleted file mode 100644
index 8efdaf8..0000000
--- a/src/java/main/org/apache/zookeeper/server/DataNode.java
+++ /dev/null
@@ -1,180 +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.zookeeper.server;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Collections;
-
-import org.apache.jute.InputArchive;
-import org.apache.jute.OutputArchive;
-import org.apache.jute.Record;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.data.StatPersisted;
-
-/**
- * This class contains the data for a node in the data tree.
- * <p>
- * A data node contains a reference to its parent, a byte array as its data, an
- * array of ACLs, a stat object, and a set of its children's paths.
- * 
- */
-public class DataNode implements Record {
-    /** the parent of this datanode */
-    DataNode parent;
-
-    /** the data for this datanode */
-    byte data[];
-
-    /**
-     * the acl map long for this datanode. the datatree has the map
-     */
-    Long acl;
-
-    /**
-     * the stat for this node that is persisted to disk.
-     */
-    public StatPersisted stat;
-
-    /**
-     * the list of children for this node. note that the list of children string
-     * does not contain the parent path -- just the last part of the path. This
-     * should be synchronized on except deserializing (for speed up issues).
-     */
-    private Set<String> children = null;
-
-    private static final Set<String> EMPTY_SET = Collections.emptySet();
-
-    /**
-     * default constructor for the datanode
-     */
-    DataNode() {
-        // default constructor
-    }
-
-    /**
-     * create a DataNode with parent, data, acls and stat
-     * 
-     * @param parent
-     *            the parent of this DataNode
-     * @param data
-     *            the data to be set
-     * @param acl
-     *            the acls for this node
-     * @param stat
-     *            the stat for this node.
-     */
-    public DataNode(DataNode parent, byte data[], Long acl, StatPersisted stat) {
-        this.parent = parent;
-        this.data = data;
-        this.acl = acl;
-        this.stat = stat;
-    }
-
-    /**
-     * Method that inserts a child into the children set
-     * 
-     * @param child
-     *            to be inserted
-     * @return true if this set did not already contain the specified element
-     */
-    public synchronized boolean addChild(String child) {
-        if (children == null) {
-            // let's be conservative on the typical number of children
-            children = new HashSet<String>(8);
-        }
-        return children.add(child);
-    }
-
-    /**
-     * Method that removes a child from the children set
-     * 
-     * @param child
-     * @return true if this set contained the specified element
-     */
-    public synchronized boolean removeChild(String child) {
-        if (children == null) {
-            return false;
-        }
-        return children.remove(child);
-    }
-
-    /**
-     * convenience method for setting the children for this datanode
-     * 
-     * @param children
-     */
-    public synchronized void setChildren(HashSet<String> children) {
-        this.children = children;
-    }
-
-    /**
-     * convenience methods to get the children
-     * 
-     * @return the children of this datanode
-     */
-    public synchronized Set<String> getChildren() {
-        if (children == null) {
-            return EMPTY_SET;
-        }
-
-        return Collections.unmodifiableSet(children);
-    }
-
-    synchronized public void copyStat(Stat to) {
-        to.setAversion(stat.getAversion());
-        to.setCtime(stat.getCtime());
-        to.setCzxid(stat.getCzxid());
-        to.setMtime(stat.getMtime());
-        to.setMzxid(stat.getMzxid());
-        to.setPzxid(stat.getPzxid());
-        to.setVersion(stat.getVersion());
-        to.setEphemeralOwner(stat.getEphemeralOwner());
-        to.setDataLength(data == null ? 0 : data.length);
-        int numChildren = 0;
-        if (this.children != null) {
-            numChildren = children.size();
-        }
-        // when we do the Cversion we need to translate from the count of the creates
-        // to the count of the changes (v3 semantics)
-        // for every create there is a delete except for the children still present
-        to.setCversion(stat.getCversion()*2 - numChildren);
-        to.setNumChildren(numChildren);
-    }
-
-    synchronized public void deserialize(InputArchive archive, String tag)
-            throws IOException {
-        archive.startRecord("node");
-        data = archive.readBuffer("data");
-        acl = archive.readLong("acl");
-        stat = new StatPersisted();
-        stat.deserialize(archive, "statpersisted");
-        archive.endRecord("node");
-    }
-
-    synchronized public void serialize(OutputArchive archive, String tag)
-            throws IOException {
-        archive.startRecord(this, "node");
-        archive.writeBuffer(data, "data");
-        archive.writeLong(acl, "acl");
-        stat.serialize(archive, "statpersisted");
-        archive.endRecord(this, "node");
-    }
-}


Mime
View raw message