Author: btellier Date: Sun Sep 20 17:13:03 2015 New Revision: 1704163 URL: http://svn.apache.org/viewvc?rev=1704163&view=rev Log: JAMES-1607 Extract Spring specific stuff out of MailboxCopierManagement -- contributed by Matthieu Baechler
Added: james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/mailbox/ james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/mailbox/SpringResolver.java Removed: james/server/trunk/data/data-api/src/main/java/org/apache/james/container/ Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java james/server/trunk/container/spring/pom.xml Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java?rev=1704163&r1=1704162&r2=1704163&view=diff ============================================================================== --- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java (original) +++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java Sun Sep 20 17:13:03 2015 @@ -18,12 +18,9 @@ ****************************************************************/ package org.apache.james.cli.probe.impl; -import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; -import org.apache.james.cli.probe.ServerProbe; -import org.apache.james.container.spring.mailbox.MailboxCopierManagementMBean; -import org.apache.james.domainlist.api.DomainListManagementMBean; -import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean; -import org.apache.james.user.api.UsersRepositoryManagementMBean; +import java.io.IOException; +import java.util.Collection; +import java.util.Map; import javax.management.MBeanServerConnection; import javax.management.MBeanServerInvocationHandler; @@ -32,9 +29,13 @@ import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; -import java.io.IOException; -import java.util.Collection; -import java.util.Map; + +import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean; +import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; +import org.apache.james.cli.probe.ServerProbe; +import org.apache.james.domainlist.api.DomainListManagementMBean; +import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean; +import org.apache.james.user.api.UsersRepositoryManagementMBean; public class JmxServerProbe implements ServerProbe { Added: james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java?rev=1704163&view=auto ============================================================================== --- james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java (added) +++ james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java Sun Sep 20 17:13:03 2015 @@ -0,0 +1,99 @@ +/**************************************************************** + * 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.adapter.mailbox; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.james.mailbox.MailboxManager; +import org.apache.james.mailbox.copier.MailboxCopier; +import org.apache.james.mailbox.exception.MailboxException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * {@link MailboxCopier} support via JMX + */ +public class MailboxCopierManagement implements MailboxCopierManagementMBean { + + /** + * The Logger. + */ + private static final Logger log = LoggerFactory.getLogger(MailboxCopierManagement.class.getName()); + + private MailboxCopier copier; + private MailboxManagerResolver resolver; + + @Inject + @Named("mailboxcopier") + @Resource(name = "mailboxcopier") + public void setMailboxCopier(MailboxCopier copier) { + this.copier = copier; + } + + @Inject + public void setMailboxManagerResolver(MailboxManagerResolver resolver) { + this.resolver = resolver; + } + + /** + * @see + * org.apache.james.container.spring.mailbox.MailboxCopierManagementMBean + * #getMailboxManagerBeans() + */ + public Map<String, String> getMailboxManagerBeans() { + Map<String, String> bMap = new HashMap<String, String>(); + Map<String, MailboxManager> beans = resolver.getMailboxManagerBeans(); + + for (Map.Entry<String, MailboxManager> entry : beans.entrySet()) { + String name = entry.getValue().getClass().getName(); + bMap.put(entry.getKey(), name); + } + + return bMap; + } + + /** + * @see + * org.apache.james.container.spring.mailbox.MailboxCopierManagementMBean + * #copy(java.lang.String, java.lang.String) + */ + public void copy(String srcBean, String dstBean) throws Exception { + if (srcBean.equals(dstBean)) + throw new IllegalArgumentException("srcBean and dstBean can not have the same name!"); + try { + copier.copyMailboxes(resolver.resolveMailboxManager(srcBean), resolver.resolveMailboxManager(dstBean)); + } catch (MailboxManagerResolverException e) { + log.error("An exception occured during the copy process", e); + throw new Exception(e.getMessage()); + } catch (MailboxException e) { + log.error("An exception occured during the copy process", e); + throw new Exception(e.getMessage()); + } catch (IOException e) { + log.error("An exception occured during the copy process", e); + throw new Exception(e.getMessage()); + } + } + +} Added: james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java?rev=1704163&view=auto ============================================================================== --- james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java (added) +++ james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java Sun Sep 20 17:13:03 2015 @@ -0,0 +1,47 @@ +/**************************************************************** + * 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.adapter.mailbox; + +import java.util.Map; + +/** + * Allow to copy {@link MailboxManager} contents from one to the other via JMX + */ +public interface MailboxCopierManagementMBean { + + /** + * Return a {@link Map} which contains the bean name of the registered + * {@link MailboxManager} instances as keys and the classname of them as + * values + * + * @return managers + */ + Map<String, String> getMailboxManagerBeans(); + + /** + * Copy from srcBean to dstBean all messages + * + * @param srcBean + * @param dstBean + * @throws Exception + * if copying failed + */ + void copy(String srcBean, String dstBean) throws Exception; + +} Added: james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java?rev=1704163&view=auto ============================================================================== --- james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java (added) +++ james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java Sun Sep 20 17:13:03 2015 @@ -0,0 +1,31 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.adapter.mailbox; + +import java.util.Map; + +import org.apache.james.mailbox.MailboxManager; + +public interface MailboxManagerResolver { + + MailboxManager resolveMailboxManager(String mailboxManagerClassName); + + Map<String, MailboxManager> getMailboxManagerBeans(); + +} \ No newline at end of file Added: james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java?rev=1704163&view=auto ============================================================================== --- james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java (added) +++ james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java Sun Sep 20 17:13:03 2015 @@ -0,0 +1,27 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.adapter.mailbox; + +public class MailboxManagerResolverException extends RuntimeException { + + public MailboxManagerResolverException(Throwable cause) { + super(cause); + } + +} \ No newline at end of file Modified: james/server/trunk/container/spring/pom.xml URL: http://svn.apache.org/viewvc/james/server/trunk/container/spring/pom.xml?rev=1704163&r1=1704162&r2=1704163&view=diff ============================================================================== --- james/server/trunk/container/spring/pom.xml (original) +++ james/server/trunk/container/spring/pom.xml Sun Sep 20 17:13:03 2015 @@ -65,6 +65,10 @@ </dependency> <dependency> <groupId>org.apache.james</groupId> + <artifactId>james-server-mailbox-adapter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-tool</artifactId> </dependency> <dependency> Added: james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/mailbox/SpringResolver.java URL: http://svn.apache.org/viewvc/james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/mailbox/SpringResolver.java?rev=1704163&view=auto ============================================================================== --- james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/mailbox/SpringResolver.java (added) +++ james/server/trunk/container/spring/src/main/java/org/apache/james/container/spring/mailbox/SpringResolver.java Sun Sep 20 17:13:03 2015 @@ -0,0 +1,62 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.container.spring.mailbox; + +import java.util.Map; + +import org.apache.james.adapter.mailbox.MailboxManagerResolver; +import org.apache.james.adapter.mailbox.MailboxManagerResolverException; +import org.apache.james.mailbox.MailboxManager; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +public class SpringResolver implements MailboxManagerResolver, ApplicationContextAware { + + private ApplicationContext context; + + /** + * @see + * org.springframework.context.ApplicationContextAware#setApplicationContext + * (org.springframework.context.ApplicationContext) + */ + public void setApplicationContext(ApplicationContext context) { + this.context = context; + } + + + @Override + public MailboxManager resolveMailboxManager(String mailboxManagerClassName) { + try { + return context.getBean(mailboxManagerClassName, MailboxManager.class); + } catch (BeansException e) { + throw new MailboxManagerResolverException(e); + } + } + + @Override + public Map<String, MailboxManager> getMailboxManagerBeans() { + try { + return context.getBeansOfType(MailboxManager.class); + } catch (BeansException e) { + throw new MailboxManagerResolverException(e); + } + } + +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org