james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [1/4] james-project git commit: JAMES-1735 Unix format
Date Wed, 18 May 2016 06:21:38 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 7015d9461 -> fed833a8f


JAMES-1735 Unix format


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e0641d5b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e0641d5b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e0641d5b

Branch: refs/heads/master
Commit: e0641d5b4c739e1d192197d216a078a7785beb9c
Parents: 7015d94
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Tue May 10 11:22:00 2016 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Tue May 17 14:46:20 2016 +0200

----------------------------------------------------------------------
 .../org/apache/james/cli/probe/ServerProbe.java | 526 +++++++--------
 .../james/cli/probe/impl/JmxServerProbe.java    | 666 +++++++++----------
 2 files changed, 596 insertions(+), 596 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e0641d5b/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
b/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
index e9d3a9b..78e665f 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
@@ -1,263 +1,263 @@
-/****************************************************************
- * 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.james.cli.probe;
-
-import java.io.Closeable;
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.james.rrt.lib.Mappings;
-
-import org.apache.james.adapter.mailbox.SerializableQuota;
-import org.apache.james.mailbox.exception.MailboxException;
-
-public interface ServerProbe extends Closeable {
-    /**
-     * Add a user to this mail server.
-     *
-     * @param userName
-     *            The name of the user being added.
-     * @param password
-     *            The password of the user being added.
-     * @throws Exception
-     */
-    void addUser(String userName, String password) throws Exception;
-
-    /**
-     * Delete a user from this mail server.
-     *
-     * @param username
-     *            The name of the user being deleted.
-     * @throws Exception
-     */
-    void removeUser(String username) throws Exception;
-
-    /**
-     * Get a List the names of all users.
-     *
-     * @return a List of all user names.
-     * @throws Exception
-     */
-    String[] listUsers() throws Exception;
-
-    /**
-     * Set a user's password.
-     *
-     * @param userName
-     *            The name of the user whose password will be changed.
-     * @param password
-     *            The new password.
-     * @throws Exception
-     */
-    void setPassword(String userName, String password) throws Exception;
-
-    /**
-     * Add domain to the service.
-     *
-     * @param domain
-     *            The domain to add.
-     * @throws Exception
-     */
-    void addDomain(String domain) throws Exception;
-
-    /**
-     * Return true if the domain exists in the service
-     *
-     * @param domain
-     *            The domain to remove.
-     * @throws Exception
-     */
-    boolean containsDomain(String domain) throws Exception;
-
-    /**
-     * Remove domain from the service
-     *
-     * @param domain
-     *            The domain to remove.
-     * @throws Exception
-     */
-    void removeDomain(String domain) throws Exception;
-
-    /**
-     * Get a list of domains for the service.
-     *
-     * @return domains an array of domains, or null if no domains exist.
-     * @throws Exception
-     */
-    String[] listDomains() throws Exception;
-
-    /**
-     * Get a Map which holds all mappings. The key is the user@domain and the
-     * value is a Collection which holds all mappings.
-     *
-     * @return a Map which holds all mappings.
-     * @throws Exception
-     */
-    Map<String, Mappings> listMappings() throws Exception;
-
-    /**
-     * Add address mapping.
-     *
-     * @param user
-     *            The username, or null if no username should be used.
-     * @param domain
-     *            The domain, or null if no domain should be used.
-     * @param toAddress
-     *            The address.
-     * @throws Exception
-     */
-    void addAddressMapping(String user, String domain, String toAddress) throws Exception;
-
-    /**
-     * Remove address mapping.
-     *
-     * @param user
-     *            The username, or null if no username should be used.
-     * @param domain
-     *            The domain, or null if no domain should be used
-     * @param fromAddress
-     *            The address.
-     * @throws Exception
-     */
-    void removeAddressMapping(String user, String domain, String fromAddress) throws Exception;
-
-    /**
-     * Return the explicit mapping stored for the given user and domain. Return
-     * null if no mapping was found
-     *
-     * @param user
-     *            The username.
-     * @param domain
-     *            The domain.
-     * @return the collection which holds the mappings, or null if no mapping is
-     *         found.
-     * @throws Exception
-     */
-    Mappings listUserDomainMappings(String user, String domain) throws Exception;
-
-    /**
-     * Remove regex mapping.
-     *
-     * @param user
-     *            The username, or null if no username should be used.
-     * @param domain
-     *            The domain, or null if no domain should be used.
-     * @param regex
-     *            The regex.
-     * @throws Exception
-     */
-    void addRegexMapping(String user, String domain, String regex) throws Exception;
-
-    /**
-     * Remove regex mapping.
-     *
-     * @param user
-     *            The username, or null if no username should be used.
-     * @param domain
-     *            The domain, or null if no domain should be used.
-     * @param regex
-     *            The regex.
-     * @throws Exception
-     */
-    void removeRegexMapping(String user, String domain, String regex) throws Exception;
-
-    /**
-     * Copy Mailbox.
-     *
-     * @param srcBean
-     *            The name of the bean that manages the source mailbox.
-     * @param dstBean
-     *            The name of the bean that manages the destination mailbox.
-     * @throws Exception
-     */
-    void copyMailbox(String srcBean, String dstBean) throws Exception;
-
-    /**
-     * Delete mailboxes Belonging to #private:${user}
-     *
-     * @param user Username of the user we want to list mailboxes on
-     * @return Collection of the mailboxes names
-     * @throws Exception
-     */
-    void deleteUserMailboxesNames(String user) throws Exception;
-
-    /**
-     * Create a mailbox
-     *
-     * @param namespace Namespace of the created mailbox
-     * @param user User of the created mailbox
-     * @param name Name of the created mailbox
-     */
-    void createMailbox(String namespace, String user, String name);
-
-    /**
-     * List mailboxes belonging to the private namespace of a user
-     *
-     * @param user The given user
-     * @return List of mailboxes belonging to the private namespace of a user
-     */
-    Collection<String> listUserMailboxes(String user);
-
-    /**
-     * Delete the given mailbox
-     *
-     * @param namespace Namespace of the mailbox to delete
-     * @param user User the mailbox to delete belongs to
-     * @param name Name of the mailbox to delete
-     */
-    void deleteMailbox(String namespace, String user, String name);
-
-    String getQuotaRoot(String namespace, String user, String name) throws MailboxException;
-
-    SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException;
-
-    SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException;
-
-    long getMaxMessageCount(String quotaRoot) throws MailboxException;
-
-    long getMaxStorage(String quotaRoot) throws MailboxException;
-
-    long getDefaultMaxMessageCount() throws MailboxException;
-
-    long getDefaultMaxStorage() throws MailboxException;
-
-    void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException;
-
-    void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException;
-
-    void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException;
-
-    void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException;
-
-    void reIndexMailbox(String namespace, String user, String name) throws Exception;
-
-    void reIndexAll() throws Exception;
-
-    long getSieveQuota() throws Exception;
-
-    void setSieveQuota(long quota) throws Exception;
-
-    void removeSieveQuota() throws Exception;
-
-    long getSieveQuota(String user) throws Exception;
-
-    void setSieveQuota(String user, long quota) throws Exception;
-
-    void removeSieveQuota(String user) throws Exception;
-}
+/****************************************************************
+ * 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.james.cli.probe;
+
+import java.io.Closeable;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.james.rrt.lib.Mappings;
+
+import org.apache.james.adapter.mailbox.SerializableQuota;
+import org.apache.james.mailbox.exception.MailboxException;
+
+public interface ServerProbe extends Closeable {
+    /**
+     * Add a user to this mail server.
+     *
+     * @param userName
+     *            The name of the user being added.
+     * @param password
+     *            The password of the user being added.
+     * @throws Exception
+     */
+    void addUser(String userName, String password) throws Exception;
+
+    /**
+     * Delete a user from this mail server.
+     *
+     * @param username
+     *            The name of the user being deleted.
+     * @throws Exception
+     */
+    void removeUser(String username) throws Exception;
+
+    /**
+     * Get a List the names of all users.
+     *
+     * @return a List of all user names.
+     * @throws Exception
+     */
+    String[] listUsers() throws Exception;
+
+    /**
+     * Set a user's password.
+     *
+     * @param userName
+     *            The name of the user whose password will be changed.
+     * @param password
+     *            The new password.
+     * @throws Exception
+     */
+    void setPassword(String userName, String password) throws Exception;
+
+    /**
+     * Add domain to the service.
+     *
+     * @param domain
+     *            The domain to add.
+     * @throws Exception
+     */
+    void addDomain(String domain) throws Exception;
+
+    /**
+     * Return true if the domain exists in the service
+     *
+     * @param domain
+     *            The domain to remove.
+     * @throws Exception
+     */
+    boolean containsDomain(String domain) throws Exception;
+
+    /**
+     * Remove domain from the service
+     *
+     * @param domain
+     *            The domain to remove.
+     * @throws Exception
+     */
+    void removeDomain(String domain) throws Exception;
+
+    /**
+     * Get a list of domains for the service.
+     *
+     * @return domains an array of domains, or null if no domains exist.
+     * @throws Exception
+     */
+    String[] listDomains() throws Exception;
+
+    /**
+     * Get a Map which holds all mappings. The key is the user@domain and the
+     * value is a Collection which holds all mappings.
+     *
+     * @return a Map which holds all mappings.
+     * @throws Exception
+     */
+    Map<String, Mappings> listMappings() throws Exception;
+
+    /**
+     * Add address mapping.
+     *
+     * @param user
+     *            The username, or null if no username should be used.
+     * @param domain
+     *            The domain, or null if no domain should be used.
+     * @param toAddress
+     *            The address.
+     * @throws Exception
+     */
+    void addAddressMapping(String user, String domain, String toAddress) throws Exception;
+
+    /**
+     * Remove address mapping.
+     *
+     * @param user
+     *            The username, or null if no username should be used.
+     * @param domain
+     *            The domain, or null if no domain should be used
+     * @param fromAddress
+     *            The address.
+     * @throws Exception
+     */
+    void removeAddressMapping(String user, String domain, String fromAddress) throws Exception;
+
+    /**
+     * Return the explicit mapping stored for the given user and domain. Return
+     * null if no mapping was found
+     *
+     * @param user
+     *            The username.
+     * @param domain
+     *            The domain.
+     * @return the collection which holds the mappings, or null if no mapping is
+     *         found.
+     * @throws Exception
+     */
+    Mappings listUserDomainMappings(String user, String domain) throws Exception;
+
+    /**
+     * Remove regex mapping.
+     *
+     * @param user
+     *            The username, or null if no username should be used.
+     * @param domain
+     *            The domain, or null if no domain should be used.
+     * @param regex
+     *            The regex.
+     * @throws Exception
+     */
+    void addRegexMapping(String user, String domain, String regex) throws Exception;
+
+    /**
+     * Remove regex mapping.
+     *
+     * @param user
+     *            The username, or null if no username should be used.
+     * @param domain
+     *            The domain, or null if no domain should be used.
+     * @param regex
+     *            The regex.
+     * @throws Exception
+     */
+    void removeRegexMapping(String user, String domain, String regex) throws Exception;
+
+    /**
+     * Copy Mailbox.
+     *
+     * @param srcBean
+     *            The name of the bean that manages the source mailbox.
+     * @param dstBean
+     *            The name of the bean that manages the destination mailbox.
+     * @throws Exception
+     */
+    void copyMailbox(String srcBean, String dstBean) throws Exception;
+
+    /**
+     * Delete mailboxes Belonging to #private:${user}
+     *
+     * @param user Username of the user we want to list mailboxes on
+     * @return Collection of the mailboxes names
+     * @throws Exception
+     */
+    void deleteUserMailboxesNames(String user) throws Exception;
+
+    /**
+     * Create a mailbox
+     *
+     * @param namespace Namespace of the created mailbox
+     * @param user User of the created mailbox
+     * @param name Name of the created mailbox
+     */
+    void createMailbox(String namespace, String user, String name);
+
+    /**
+     * List mailboxes belonging to the private namespace of a user
+     *
+     * @param user The given user
+     * @return List of mailboxes belonging to the private namespace of a user
+     */
+    Collection<String> listUserMailboxes(String user);
+
+    /**
+     * Delete the given mailbox
+     *
+     * @param namespace Namespace of the mailbox to delete
+     * @param user User the mailbox to delete belongs to
+     * @param name Name of the mailbox to delete
+     */
+    void deleteMailbox(String namespace, String user, String name);
+
+    String getQuotaRoot(String namespace, String user, String name) throws MailboxException;
+
+    SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException;
+
+    SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException;
+
+    long getMaxMessageCount(String quotaRoot) throws MailboxException;
+
+    long getMaxStorage(String quotaRoot) throws MailboxException;
+
+    long getDefaultMaxMessageCount() throws MailboxException;
+
+    long getDefaultMaxStorage() throws MailboxException;
+
+    void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException;
+
+    void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException;
+
+    void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException;
+
+    void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException;
+
+    void reIndexMailbox(String namespace, String user, String name) throws Exception;
+
+    void reIndexAll() throws Exception;
+
+    long getSieveQuota() throws Exception;
+
+    void setSieveQuota(long quota) throws Exception;
+
+    void removeSieveQuota() throws Exception;
+
+    long getSieveQuota(String user) throws Exception;
+
+    void setSieveQuota(String user, long quota) throws Exception;
+
+    void removeSieveQuota(String user) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0641d5b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
index 3877b39..4a7dee0 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
@@ -1,333 +1,333 @@
-/****************************************************************
- * 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.james.cli.probe.impl;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Map;
-
-import javax.management.MBeanServerConnection;
-import javax.management.MBeanServerInvocationHandler;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean;
-import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean;
-import org.apache.james.adapter.mailbox.QuotaManagementMBean;
-import org.apache.james.adapter.mailbox.ReIndexerManagementMBean;
-import org.apache.james.adapter.mailbox.SerializableQuota;
-import org.apache.james.cli.probe.ServerProbe;
-import org.apache.james.domainlist.api.DomainListManagementMBean;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean;
-import org.apache.james.rrt.lib.Mappings;
-import org.apache.james.sieverepository.api.SieveRepositoryManagementMBean;
-import org.apache.james.user.api.UsersRepositoryManagementMBean;
-
-public class JmxServerProbe implements ServerProbe {
-
-    // TODO: Move this to somewhere else
-    private final static String DOMAINLIST_OBJECT_NAME = "org.apache.james:type=component,name=domainlist";
-    private final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable";
-    private final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository";
-    private final static String MAILBOXCOPIER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxcopier";
-    private final static String MAILBOXMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxmanagerbean";
-    private final static String SIEVEMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=sievemanagerbean";
-    private final static String QUOTAMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=quotamanagerbean";
-    private final static String REINDEXER_OBJECT_NAME = "org.apache.james:type=component,name=reindexerbean";
-
-    private JMXConnector jmxc;
-    
-    private DomainListManagementMBean domainListProcxy;
-    private RecipientRewriteTableManagementMBean virtualUserTableProxy;
-    private UsersRepositoryManagementMBean usersRepositoryProxy;
-    private MailboxCopierManagementMBean mailboxCopierManagement;
-    private MailboxManagerManagementMBean mailboxManagerManagement;
-    private QuotaManagementMBean quotaManagement;
-    private ReIndexerManagementMBean reIndexerManagement;
-    private SieveRepositoryManagementMBean sieveRepositoryManagement;
-
-    private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi";
-    private static final int defaultPort = 9999;
-    private final String host;
-    private final int port;
-
-    /**
-     * Creates a ServerProbe using the specified JMX host and port.
-     *
-     * @param host hostname or IP address of the JMX agent
-     * @param port TCP port of the remote JMX agent
-     * @throws IOException on connection failures
-     */
-    public JmxServerProbe(String host, int port) throws IOException {
-        this.host = host;
-        this.port = port;
-        connect();
-    }
-
-    /**
-     * Creates a NodeProbe using the specified JMX host and default port.
-     *
-     * @param host hostname or IP address of the JMX agent
-     * @throws IOException on connection failures
-     */
-    public JmxServerProbe(String host) throws IOException {
-        this.host = host;
-        this.port = defaultPort;
-        connect();
-    }
-
-    /**
-     * Create a connection to the JMX agent and setup the M[X]Bean proxies.
-     *
-     * @throws IOException on connection failures
-     */
-    private void connect() throws IOException {
-        JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
-        jmxc = JMXConnectorFactory.connect(jmxUrl, null);
-        MBeanServerConnection mbeanServerConn = jmxc.getMBeanServerConnection();
-        
-        try {
-            ObjectName name = new ObjectName(DOMAINLIST_OBJECT_NAME);
-            domainListProcxy = MBeanServerInvocationHandler.newProxyInstance(
-                    mbeanServerConn, name, DomainListManagementMBean.class, true);
-            name = new ObjectName(VIRTUALUSERTABLE_OBJECT_NAME);
-            virtualUserTableProxy = MBeanServerInvocationHandler
-                    .newProxyInstance(mbeanServerConn, name, RecipientRewriteTableManagementMBean.class,
true);
-            name = new ObjectName(USERSREPOSITORY_OBJECT_NAME);
-            usersRepositoryProxy = MBeanServerInvocationHandler.newProxyInstance(
-                    mbeanServerConn, name, UsersRepositoryManagementMBean.class, true);
-            name = new ObjectName(MAILBOXCOPIER_OBJECT_NAME);
-            mailboxCopierManagement = MBeanServerInvocationHandler.newProxyInstance(
-                    mbeanServerConn, name, MailboxCopierManagementMBean.class, true);
-            name = new ObjectName(MAILBOXMANAGER_OBJECT_NAME);
-            mailboxManagerManagement = MBeanServerInvocationHandler.newProxyInstance(
-                    mbeanServerConn, name, MailboxManagerManagementMBean.class, true);
-            name = new ObjectName(QUOTAMANAGER_OBJECT_NAME);
-            quotaManagement = MBeanServerInvocationHandler.newProxyInstance(
-                    mbeanServerConn, name, QuotaManagementMBean.class, true);
-            name = new ObjectName(REINDEXER_OBJECT_NAME);
-            reIndexerManagement = MBeanServerInvocationHandler.newProxyInstance(
-                mbeanServerConn, name, ReIndexerManagementMBean.class, true);
-            name = new ObjectName(SIEVEMANAGER_OBJECT_NAME);
-            sieveRepositoryManagement = MBeanServerInvocationHandler.newProxyInstance(
-                mbeanServerConn, name, SieveRepositoryManagementMBean.class, true);
-        } catch (MalformedObjectNameException e) {
-            throw new RuntimeException("Invalid ObjectName? Please report this as a bug.",
e);
-        }
-    }
-
-    @Override
-    public void close() throws IOException {
-        jmxc.close();
-    }
-    
-    @Override
-    public void addUser(String userName, String password) throws Exception {
-        usersRepositoryProxy.addUser(userName, password);
-    }
-
-    @Override
-    public void removeUser(String username) throws Exception {
-        usersRepositoryProxy.deleteUser(username);
-    }
-
-    @Override
-    public String[] listUsers() throws Exception {
-        return usersRepositoryProxy.listAllUsers();
-    }
-
-    @Override
-    public void setPassword(String userName, String password) throws Exception {
-        usersRepositoryProxy.setPassword(userName, password);
-    }
-
-    @Override
-    public boolean containsDomain(String domain) throws Exception {
-        return domainListProcxy.containsDomain(domain);
-    }
-
-    @Override
-    public void addDomain(String domain) throws Exception {
-        domainListProcxy.addDomain(domain);
-    }
-
-    @Override
-    public void removeDomain(String domain) throws Exception {
-        domainListProcxy.removeDomain(domain);
-    }
-
-    @Override
-    public String[] listDomains() throws Exception {
-        return domainListProcxy.getDomains();
-    }
-
-    @Override
-    public Map<String, Mappings> listMappings() throws Exception {
-        return virtualUserTableProxy.getAllMappings();
-    }
-
-    @Override
-    public void addAddressMapping(String user, String domain, String toAddress) throws Exception
{
-        virtualUserTableProxy.addAddressMapping(user, domain, toAddress);
-    }
-
-    @Override
-    public void removeAddressMapping(String user, String domain, String fromAddress) throws
Exception {
-        virtualUserTableProxy.removeAddressMapping(user, domain, fromAddress);
-    }
-
-    @Override
-    public Mappings listUserDomainMappings(String user, String domain) throws Exception {
-        return virtualUserTableProxy.getUserDomainMappings(user, domain);
-    }
-
-    @Override
-    public void addRegexMapping(String user, String domain, String regex) throws Exception
{
-        virtualUserTableProxy.addRegexMapping(user, domain, regex);
-    }
-
-    @Override
-    public void removeRegexMapping(String user, String domain, String regex) throws Exception
{
-        virtualUserTableProxy.removeRegexMapping(user, domain, regex);
-    }
-
-    @Override
-    public void copyMailbox(String srcBean, String dstBean) throws Exception {
-        mailboxCopierManagement.copy(srcBean, dstBean);
-    }
-
-    @Override
-    public void deleteUserMailboxesNames(String user) throws Exception {
-        mailboxManagerManagement.deleteMailboxes(user);
-    }
-
-    @Override
-    public void createMailbox(String namespace, String user, String name) {
-        mailboxManagerManagement.createMailbox(namespace, user, name);
-    }
-
-    @Override
-    public Collection<String> listUserMailboxes(String user) {
-        return mailboxManagerManagement.listMailboxes(user);
-    }
-
-    @Override
-    public void deleteMailbox(String namespace, String user, String name) {
-        mailboxManagerManagement.deleteMailbox(namespace, user, name);
-    }
-
-    @Override
-    public String getQuotaRoot(String namespace, String user, String name) throws MailboxException
{
-        return quotaManagement.getQuotaRoot(namespace, user, name);
-    }
-
-    @Override
-    public SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException
{
-        return quotaManagement.getMessageCountQuota(quotaRoot);
-    }
-
-    @Override
-    public SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException {
-        return quotaManagement.getStorageQuota(quotaRoot);
-    }
-
-    @Override
-    public long getMaxMessageCount(String quotaRoot) throws MailboxException {
-        return quotaManagement.getMaxMessageCount(quotaRoot);
-    }
-
-    @Override
-    public long getMaxStorage(String quotaRoot) throws MailboxException {
-        return quotaManagement.getMaxStorage(quotaRoot);
-    }
-
-    @Override
-    public long getDefaultMaxMessageCount() throws MailboxException {
-        return quotaManagement.getDefaultMaxMessageCount();
-    }
-
-    @Override
-    public long getDefaultMaxStorage() throws MailboxException {
-        return quotaManagement.getDefaultMaxStorage();
-    }
-
-    @Override
-    public void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException
{
-        quotaManagement.setMaxMessageCount(quotaRoot, maxMessageCount);
-    }
-
-    @Override
-    public void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException {
-        quotaManagement.setMaxStorage(quotaRoot, maxSize);
-    }
-
-    @Override
-    public void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException
{
-        quotaManagement.setDefaultMaxMessageCount(maxDefaultMessageCount);
-    }
-
-    @Override
-    public void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException {
-        quotaManagement.setDefaultMaxStorage(maxDefaultSize);
-    }
-
-    @Override
-    public void reIndexMailbox(String namespace, String user, String name) throws Exception
{
-        reIndexerManagement.reIndex(namespace, user, name);
-    }
-
-    @Override
-    public void reIndexAll() throws Exception {
-        reIndexerManagement.reIndex();
-    }
-
-    @Override
-    public long getSieveQuota() throws Exception {
-        return sieveRepositoryManagement.getQuota();
-    }
-
-    @Override
-    public void setSieveQuota(long quota) throws Exception {
-        sieveRepositoryManagement.setQuota(quota);
-    }
-
-    @Override
-    public void removeSieveQuota() throws Exception {
-        sieveRepositoryManagement.removeQuota();
-    }
-
-    @Override
-    public long getSieveQuota(String user) throws Exception {
-        return sieveRepositoryManagement.getQuota(user);
-    }
-
-    @Override
-    public void setSieveQuota(String user, long quota) throws Exception {
-        sieveRepositoryManagement.setQuota(user, quota);
-    }
-
-    @Override
-    public void removeSieveQuota(String user) throws Exception {
-        sieveRepositoryManagement.removeQuota(user);
-    }
-}
+/****************************************************************
+ * 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.james.cli.probe.impl;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean;
+import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean;
+import org.apache.james.adapter.mailbox.QuotaManagementMBean;
+import org.apache.james.adapter.mailbox.ReIndexerManagementMBean;
+import org.apache.james.adapter.mailbox.SerializableQuota;
+import org.apache.james.cli.probe.ServerProbe;
+import org.apache.james.domainlist.api.DomainListManagementMBean;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean;
+import org.apache.james.rrt.lib.Mappings;
+import org.apache.james.sieverepository.api.SieveRepositoryManagementMBean;
+import org.apache.james.user.api.UsersRepositoryManagementMBean;
+
+public class JmxServerProbe implements ServerProbe {
+
+    // TODO: Move this to somewhere else
+    private final static String DOMAINLIST_OBJECT_NAME = "org.apache.james:type=component,name=domainlist";
+    private final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable";
+    private final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository";
+    private final static String MAILBOXCOPIER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxcopier";
+    private final static String MAILBOXMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxmanagerbean";
+    private final static String SIEVEMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=sievemanagerbean";
+    private final static String QUOTAMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=quotamanagerbean";
+    private final static String REINDEXER_OBJECT_NAME = "org.apache.james:type=component,name=reindexerbean";
+
+    private JMXConnector jmxc;
+    
+    private DomainListManagementMBean domainListProcxy;
+    private RecipientRewriteTableManagementMBean virtualUserTableProxy;
+    private UsersRepositoryManagementMBean usersRepositoryProxy;
+    private MailboxCopierManagementMBean mailboxCopierManagement;
+    private MailboxManagerManagementMBean mailboxManagerManagement;
+    private QuotaManagementMBean quotaManagement;
+    private ReIndexerManagementMBean reIndexerManagement;
+    private SieveRepositoryManagementMBean sieveRepositoryManagement;
+
+    private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi";
+    private static final int defaultPort = 9999;
+    private final String host;
+    private final int port;
+
+    /**
+     * Creates a ServerProbe using the specified JMX host and port.
+     *
+     * @param host hostname or IP address of the JMX agent
+     * @param port TCP port of the remote JMX agent
+     * @throws IOException on connection failures
+     */
+    public JmxServerProbe(String host, int port) throws IOException {
+        this.host = host;
+        this.port = port;
+        connect();
+    }
+
+    /**
+     * Creates a NodeProbe using the specified JMX host and default port.
+     *
+     * @param host hostname or IP address of the JMX agent
+     * @throws IOException on connection failures
+     */
+    public JmxServerProbe(String host) throws IOException {
+        this.host = host;
+        this.port = defaultPort;
+        connect();
+    }
+
+    /**
+     * Create a connection to the JMX agent and setup the M[X]Bean proxies.
+     *
+     * @throws IOException on connection failures
+     */
+    private void connect() throws IOException {
+        JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
+        jmxc = JMXConnectorFactory.connect(jmxUrl, null);
+        MBeanServerConnection mbeanServerConn = jmxc.getMBeanServerConnection();
+        
+        try {
+            ObjectName name = new ObjectName(DOMAINLIST_OBJECT_NAME);
+            domainListProcxy = MBeanServerInvocationHandler.newProxyInstance(
+                    mbeanServerConn, name, DomainListManagementMBean.class, true);
+            name = new ObjectName(VIRTUALUSERTABLE_OBJECT_NAME);
+            virtualUserTableProxy = MBeanServerInvocationHandler
+                    .newProxyInstance(mbeanServerConn, name, RecipientRewriteTableManagementMBean.class,
true);
+            name = new ObjectName(USERSREPOSITORY_OBJECT_NAME);
+            usersRepositoryProxy = MBeanServerInvocationHandler.newProxyInstance(
+                    mbeanServerConn, name, UsersRepositoryManagementMBean.class, true);
+            name = new ObjectName(MAILBOXCOPIER_OBJECT_NAME);
+            mailboxCopierManagement = MBeanServerInvocationHandler.newProxyInstance(
+                    mbeanServerConn, name, MailboxCopierManagementMBean.class, true);
+            name = new ObjectName(MAILBOXMANAGER_OBJECT_NAME);
+            mailboxManagerManagement = MBeanServerInvocationHandler.newProxyInstance(
+                    mbeanServerConn, name, MailboxManagerManagementMBean.class, true);
+            name = new ObjectName(QUOTAMANAGER_OBJECT_NAME);
+            quotaManagement = MBeanServerInvocationHandler.newProxyInstance(
+                    mbeanServerConn, name, QuotaManagementMBean.class, true);
+            name = new ObjectName(REINDEXER_OBJECT_NAME);
+            reIndexerManagement = MBeanServerInvocationHandler.newProxyInstance(
+                mbeanServerConn, name, ReIndexerManagementMBean.class, true);
+            name = new ObjectName(SIEVEMANAGER_OBJECT_NAME);
+            sieveRepositoryManagement = MBeanServerInvocationHandler.newProxyInstance(
+                mbeanServerConn, name, SieveRepositoryManagementMBean.class, true);
+        } catch (MalformedObjectNameException e) {
+            throw new RuntimeException("Invalid ObjectName? Please report this as a bug.",
e);
+        }
+    }
+
+    @Override
+    public void close() throws IOException {
+        jmxc.close();
+    }
+    
+    @Override
+    public void addUser(String userName, String password) throws Exception {
+        usersRepositoryProxy.addUser(userName, password);
+    }
+
+    @Override
+    public void removeUser(String username) throws Exception {
+        usersRepositoryProxy.deleteUser(username);
+    }
+
+    @Override
+    public String[] listUsers() throws Exception {
+        return usersRepositoryProxy.listAllUsers();
+    }
+
+    @Override
+    public void setPassword(String userName, String password) throws Exception {
+        usersRepositoryProxy.setPassword(userName, password);
+    }
+
+    @Override
+    public boolean containsDomain(String domain) throws Exception {
+        return domainListProcxy.containsDomain(domain);
+    }
+
+    @Override
+    public void addDomain(String domain) throws Exception {
+        domainListProcxy.addDomain(domain);
+    }
+
+    @Override
+    public void removeDomain(String domain) throws Exception {
+        domainListProcxy.removeDomain(domain);
+    }
+
+    @Override
+    public String[] listDomains() throws Exception {
+        return domainListProcxy.getDomains();
+    }
+
+    @Override
+    public Map<String, Mappings> listMappings() throws Exception {
+        return virtualUserTableProxy.getAllMappings();
+    }
+
+    @Override
+    public void addAddressMapping(String user, String domain, String toAddress) throws Exception
{
+        virtualUserTableProxy.addAddressMapping(user, domain, toAddress);
+    }
+
+    @Override
+    public void removeAddressMapping(String user, String domain, String fromAddress) throws
Exception {
+        virtualUserTableProxy.removeAddressMapping(user, domain, fromAddress);
+    }
+
+    @Override
+    public Mappings listUserDomainMappings(String user, String domain) throws Exception {
+        return virtualUserTableProxy.getUserDomainMappings(user, domain);
+    }
+
+    @Override
+    public void addRegexMapping(String user, String domain, String regex) throws Exception
{
+        virtualUserTableProxy.addRegexMapping(user, domain, regex);
+    }
+
+    @Override
+    public void removeRegexMapping(String user, String domain, String regex) throws Exception
{
+        virtualUserTableProxy.removeRegexMapping(user, domain, regex);
+    }
+
+    @Override
+    public void copyMailbox(String srcBean, String dstBean) throws Exception {
+        mailboxCopierManagement.copy(srcBean, dstBean);
+    }
+
+    @Override
+    public void deleteUserMailboxesNames(String user) throws Exception {
+        mailboxManagerManagement.deleteMailboxes(user);
+    }
+
+    @Override
+    public void createMailbox(String namespace, String user, String name) {
+        mailboxManagerManagement.createMailbox(namespace, user, name);
+    }
+
+    @Override
+    public Collection<String> listUserMailboxes(String user) {
+        return mailboxManagerManagement.listMailboxes(user);
+    }
+
+    @Override
+    public void deleteMailbox(String namespace, String user, String name) {
+        mailboxManagerManagement.deleteMailbox(namespace, user, name);
+    }
+
+    @Override
+    public String getQuotaRoot(String namespace, String user, String name) throws MailboxException
{
+        return quotaManagement.getQuotaRoot(namespace, user, name);
+    }
+
+    @Override
+    public SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException
{
+        return quotaManagement.getMessageCountQuota(quotaRoot);
+    }
+
+    @Override
+    public SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException {
+        return quotaManagement.getStorageQuota(quotaRoot);
+    }
+
+    @Override
+    public long getMaxMessageCount(String quotaRoot) throws MailboxException {
+        return quotaManagement.getMaxMessageCount(quotaRoot);
+    }
+
+    @Override
+    public long getMaxStorage(String quotaRoot) throws MailboxException {
+        return quotaManagement.getMaxStorage(quotaRoot);
+    }
+
+    @Override
+    public long getDefaultMaxMessageCount() throws MailboxException {
+        return quotaManagement.getDefaultMaxMessageCount();
+    }
+
+    @Override
+    public long getDefaultMaxStorage() throws MailboxException {
+        return quotaManagement.getDefaultMaxStorage();
+    }
+
+    @Override
+    public void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException
{
+        quotaManagement.setMaxMessageCount(quotaRoot, maxMessageCount);
+    }
+
+    @Override
+    public void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException {
+        quotaManagement.setMaxStorage(quotaRoot, maxSize);
+    }
+
+    @Override
+    public void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException
{
+        quotaManagement.setDefaultMaxMessageCount(maxDefaultMessageCount);
+    }
+
+    @Override
+    public void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException {
+        quotaManagement.setDefaultMaxStorage(maxDefaultSize);
+    }
+
+    @Override
+    public void reIndexMailbox(String namespace, String user, String name) throws Exception
{
+        reIndexerManagement.reIndex(namespace, user, name);
+    }
+
+    @Override
+    public void reIndexAll() throws Exception {
+        reIndexerManagement.reIndex();
+    }
+
+    @Override
+    public long getSieveQuota() throws Exception {
+        return sieveRepositoryManagement.getQuota();
+    }
+
+    @Override
+    public void setSieveQuota(long quota) throws Exception {
+        sieveRepositoryManagement.setQuota(quota);
+    }
+
+    @Override
+    public void removeSieveQuota() throws Exception {
+        sieveRepositoryManagement.removeQuota();
+    }
+
+    @Override
+    public long getSieveQuota(String user) throws Exception {
+        return sieveRepositoryManagement.getQuota(user);
+    }
+
+    @Override
+    public void setSieveQuota(String user, long quota) throws Exception {
+        sieveRepositoryManagement.setQuota(user, quota);
+    }
+
+    @Override
+    public void removeSieveQuota(String user) throws Exception {
+        sieveRepositoryManagement.removeQuota(user);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message