http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/DeterminedRouter.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/DeterminedRouter.java b/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/DeterminedRouter.java index b22dc08..86c6b89 100755 --- a/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/DeterminedRouter.java +++ b/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/DeterminedRouter.java @@ -1,107 +1,107 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamicdatasourcerouting; - -import org.apache.openejb.resource.jdbc.router.AbstractRouter; - -import javax.naming.NamingException; -import javax.sql.DataSource; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public class DeterminedRouter extends AbstractRouter { - - private String dataSourceNames; - private String defaultDataSourceName; - private Map<String, DataSource> dataSources = null; - private ThreadLocal<DataSource> currentDataSource = new ThreadLocal<DataSource>(); - - /** - * @param datasourceList datasource resource name, separator is a space - */ - public void setDataSourceNames(String datasourceList) { - dataSourceNames = datasourceList; - } - - /** - * lookup datasource in openejb resources - */ - private void init() { - dataSources = new ConcurrentHashMap<String, DataSource>(); - for (String ds : dataSourceNames.split(" ")) { - try { - Object o = getOpenEJBResource(ds); - if (o instanceof DataSource) { - dataSources.put(ds, DataSource.class.cast(o)); - } - } catch (NamingException e) { - // ignored - } - } - } - - /** - * @return the user selected data source if it is set - * or the default one - * @throws IllegalArgumentException if the data source is not found - */ - @Override - public DataSource getDataSource() { - // lazy init of routed datasources - if (dataSources == null) { - init(); - } - - // if no datasource is selected use the default one - if (currentDataSource.get() == null) { - if (dataSources.containsKey(defaultDataSourceName)) { - return dataSources.get(defaultDataSourceName); - - } else { - throw new IllegalArgumentException("you have to specify at least one datasource"); - } - } - - // the developper set the datasource to use - return currentDataSource.get(); - } - - /** - * @param datasourceName data source name - */ - public void setDataSource(String datasourceName) { - if (dataSources == null) { - init(); - } - if (!dataSources.containsKey(datasourceName)) { - throw new IllegalArgumentException("data source called " + datasourceName + " can't be found."); - } - DataSource ds = dataSources.get(datasourceName); - currentDataSource.set(ds); - } - - /** - * reset the data source - */ - public void clear() { - currentDataSource.remove(); - } - - public void setDefaultDataSourceName(String name) { - this.defaultDataSourceName = name; - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamicdatasourcerouting; + +import org.apache.openejb.resource.jdbc.router.AbstractRouter; + +import javax.naming.NamingException; +import javax.sql.DataSource; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class DeterminedRouter extends AbstractRouter { + + private String dataSourceNames; + private String defaultDataSourceName; + private Map<String, DataSource> dataSources = null; + private ThreadLocal<DataSource> currentDataSource = new ThreadLocal<DataSource>(); + + /** + * @param datasourceList datasource resource name, separator is a space + */ + public void setDataSourceNames(String datasourceList) { + dataSourceNames = datasourceList; + } + + /** + * lookup datasource in openejb resources + */ + private void init() { + dataSources = new ConcurrentHashMap<String, DataSource>(); + for (String ds : dataSourceNames.split(" ")) { + try { + Object o = getOpenEJBResource(ds); + if (o instanceof DataSource) { + dataSources.put(ds, DataSource.class.cast(o)); + } + } catch (NamingException e) { + // ignored + } + } + } + + /** + * @return the user selected data source if it is set + * or the default one + * @throws IllegalArgumentException if the data source is not found + */ + @Override + public DataSource getDataSource() { + // lazy init of routed datasources + if (dataSources == null) { + init(); + } + + // if no datasource is selected use the default one + if (currentDataSource.get() == null) { + if (dataSources.containsKey(defaultDataSourceName)) { + return dataSources.get(defaultDataSourceName); + + } else { + throw new IllegalArgumentException("you have to specify at least one datasource"); + } + } + + // the developper set the datasource to use + return currentDataSource.get(); + } + + /** + * @param datasourceName data source name + */ + public void setDataSource(String datasourceName) { + if (dataSources == null) { + init(); + } + if (!dataSources.containsKey(datasourceName)) { + throw new IllegalArgumentException("data source called " + datasourceName + " can't be found."); + } + DataSource ds = dataSources.get(datasourceName); + currentDataSource.set(ds); + } + + /** + * reset the data source + */ + public void clear() { + currentDataSource.remove(); + } + + public void setDefaultDataSourceName(String name) { + this.defaultDataSourceName = name; + } +}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/Person.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/Person.java b/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/Person.java index 00e3b89..636ed2a 100755 --- a/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/Person.java +++ b/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/Person.java @@ -1,53 +1,53 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamicdatasourcerouting; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -public class Person { - - @Id - private long id; - private String name; - - public Person() { - // no-op - } - - public Person(int i, String n) { - id = i; - name = n; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamicdatasourcerouting; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Person { + + @Id + private long id; + private String name; + + public Person() { + // no-op + } + + public Person(int i, String n) { + id = i; + name = n; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/RoutedPersister.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/RoutedPersister.java b/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/RoutedPersister.java index d2398a6..13b862b 100755 --- a/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/RoutedPersister.java +++ b/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/RoutedPersister.java @@ -1,37 +1,37 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamicdatasourcerouting; - -import javax.annotation.Resource; -import javax.ejb.Stateless; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - -@Stateless -public class RoutedPersister { - - @PersistenceContext(unitName = "router") - private EntityManager em; - - @Resource(name = "My Router", type = DeterminedRouter.class) - private DeterminedRouter router; - - public void persist(int id, String name, String ds) { - router.setDataSource(ds); - em.persist(new Person(id, name)); - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamicdatasourcerouting; + +import javax.annotation.Resource; +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +@Stateless +public class RoutedPersister { + + @PersistenceContext(unitName = "router") + private EntityManager em; + + @Resource(name = "My Router", type = DeterminedRouter.class) + private DeterminedRouter router; + + public void persist(int id, String name, String ds) { + router.setDataSource(ds); + em.persist(new Person(id, name)); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-implementation/src/main/java/org/superbiz/dynamic/SocialInterceptor.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-implementation/src/main/java/org/superbiz/dynamic/SocialInterceptor.java b/examples/dynamic-implementation/src/main/java/org/superbiz/dynamic/SocialInterceptor.java index d43c4e0..3e0a748 100644 --- a/examples/dynamic-implementation/src/main/java/org/superbiz/dynamic/SocialInterceptor.java +++ b/examples/dynamic-implementation/src/main/java/org/superbiz/dynamic/SocialInterceptor.java @@ -1,40 +1,40 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamic; - -import javax.interceptor.AroundInvoke; -import javax.interceptor.InvocationContext; - -public class SocialInterceptor { - - @AroundInvoke - public Object around(InvocationContext context) throws Exception { - String mtd = context.getMethod().getName(); - String address; - if (mtd.toLowerCase().contains("facebook")) { - address = "http://www.facebook.com"; - } else if (mtd.toLowerCase().contains("twitter")) { - address = "http://twitter.com"; - } else { - address = "no website for you"; - } - - System.out.println("go on " + address); - return context.proceed(); - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamic; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +public class SocialInterceptor { + + @AroundInvoke + public Object around(InvocationContext context) throws Exception { + String mtd = context.getMethod().getName(); + String address; + if (mtd.toLowerCase().contains("facebook")) { + address = "http://www.facebook.com"; + } else if (mtd.toLowerCase().contains("twitter")) { + address = "http://twitter.com"; + } else { + address = "no website for you"; + } + + System.out.println("go on " + address); + return context.proceed(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/DynamicMBeanHandler.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/DynamicMBeanHandler.java b/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/DynamicMBeanHandler.java index d07a705..63046da 100644 --- a/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/DynamicMBeanHandler.java +++ b/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/DynamicMBeanHandler.java @@ -1,260 +1,260 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamic.mbean; - -import javax.annotation.PreDestroy; -import javax.management.Attribute; -import javax.management.MBeanAttributeInfo; -import javax.management.MBeanInfo; -import javax.management.MBeanServer; -import javax.management.MBeanServerConnection; -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.lang.management.ManagementFactory; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Need a @PreDestroy method to disconnect the remote host when used in remote mode. - */ -public class DynamicMBeanHandler implements InvocationHandler { - - private final Map<Method, ConnectionInfo> infos = new ConcurrentHashMap<Method, ConnectionInfo>(); - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - final String methodName = method.getName(); - if (method.getDeclaringClass().equals(Object.class) && "toString".equals(methodName)) { - return getClass().getSimpleName() + " Proxy"; - } - if (method.getAnnotation(PreDestroy.class) != null) { - return destroy(); - } - - final ConnectionInfo info = getConnectionInfo(method); - final MBeanInfo infos = info.getMBeanInfo(); - if (methodName.startsWith("set") && methodName.length() > 3 && args != null && args.length == 1 - && (Void.TYPE.equals(method.getReturnType()) || Void.class.equals(method.getReturnType()))) { - final String attributeName = attributeName(infos, methodName, method.getParameterTypes()[0]); - info.setAttribute(new Attribute(attributeName, args[0])); - return null; - } else if (methodName.startsWith("get") && (args == null || args.length == 0) && methodName.length() > 3) { - final String attributeName = attributeName(infos, methodName, method.getReturnType()); - return info.getAttribute(attributeName); - } - // operation - return info.invoke(methodName, args, getSignature(method)); - } - - public Object destroy() { - for (ConnectionInfo info : infos.values()) { - info.clean(); - } - infos.clear(); - return null; - } - - private String[] getSignature(Method method) { - String[] args = new String[method.getParameterTypes().length]; - for (int i = 0; i < method.getParameterTypes().length; i++) { - args[i] = method.getParameterTypes()[i].getName(); - } - return args; // note: null should often work... - } - - private String attributeName(MBeanInfo infos, String methodName, Class<?> type) { - String found = null; - String foundBackUp = null; // without checking the type - final String attributeName = methodName.substring(3, methodName.length()); - final String lowerName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4, methodName.length()); - - for (MBeanAttributeInfo attribute : infos.getAttributes()) { - final String name = attribute.getName(); - if (attributeName.equals(name)) { - foundBackUp = attributeName; - if (attribute.getType().equals(type.getName())) { - found = name; - } - } else if (found == null && ((lowerName.equals(name) && !attributeName.equals(name)) - || lowerName.equalsIgnoreCase(name))) { - foundBackUp = name; - if (attribute.getType().equals(type.getName())) { - found = name; - } - } - } - - if (found == null && foundBackUp == null) { - throw new UnsupportedOperationException("cannot find attribute " + attributeName); - } - - if (found != null) { - return found; - } - return foundBackUp; - } - - private synchronized ConnectionInfo getConnectionInfo(Method method) throws Exception { - if (!infos.containsKey(method)) { - synchronized (infos) { - if (!infos.containsKey(method)) { // double check for synchro - org.superbiz.dynamic.mbean.ObjectName on = method.getAnnotation(org.superbiz.dynamic.mbean.ObjectName.class); - if (on == null) { - Class<?> current = method.getDeclaringClass(); - do { - on = method.getDeclaringClass().getAnnotation(org.superbiz.dynamic.mbean.ObjectName.class); - current = current.getSuperclass(); - } while (on == null && current != null); - if (on == null) { - throw new UnsupportedOperationException("class or method should define the objectName to use for invocation: " + method.toGenericString()); - } - } - final ConnectionInfo info; - if (on.url().isEmpty()) { - info = new LocalConnectionInfo(); - ((LocalConnectionInfo) info).server = ManagementFactory.getPlatformMBeanServer(); // could use an id... - } else { - info = new RemoteConnectionInfo(); - final Map<String, String[]> environment = new HashMap<String, String[]>(); - if (!on.user().isEmpty()) { - environment.put(JMXConnector.CREDENTIALS, new String[]{on.user(), on.password()}); - } - // ((RemoteConnectionInfo) info).connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(on.url()), environment); - ((RemoteConnectionInfo) info).connector = JMXConnectorFactory.connect(new JMXServiceURL(on.url()), environment); - - } - info.objectName = new ObjectName(on.value()); - - infos.put(method, info); - } - } - } - return infos.get(method); - } - - private abstract static class ConnectionInfo { - - protected ObjectName objectName; - - public abstract void setAttribute(Attribute attribute) throws Exception; - - public abstract Object getAttribute(String attribute) throws Exception; - - public abstract Object invoke(String operationName, Object params[], String signature[]) throws Exception; - - public abstract MBeanInfo getMBeanInfo() throws Exception; - - public abstract void clean(); - } - - private static class LocalConnectionInfo extends ConnectionInfo { - - private MBeanServer server; - - @Override - public void setAttribute(Attribute attribute) throws Exception { - server.setAttribute(objectName, attribute); - } - - @Override - public Object getAttribute(String attribute) throws Exception { - return server.getAttribute(objectName, attribute); - } - - @Override - public Object invoke(String operationName, Object[] params, String[] signature) throws Exception { - return server.invoke(objectName, operationName, params, signature); - } - - @Override - public MBeanInfo getMBeanInfo() throws Exception { - return server.getMBeanInfo(objectName); - } - - @Override - public void clean() { - // no-op - } - } - - private static class RemoteConnectionInfo extends ConnectionInfo { - - private JMXConnector connector; - private MBeanServerConnection connection; - - private void before() throws IOException { - connection = connector.getMBeanServerConnection(); - } - - private void after() throws IOException { - // no-op - } - - @Override - public void setAttribute(Attribute attribute) throws Exception { - before(); - connection.setAttribute(objectName, attribute); - after(); - } - - @Override - public Object getAttribute(String attribute) throws Exception { - before(); - try { - return connection.getAttribute(objectName, attribute); - } finally { - after(); - } - } - - @Override - public Object invoke(String operationName, Object[] params, String[] signature) throws Exception { - before(); - try { - return connection.invoke(objectName, operationName, params, signature); - } finally { - after(); - } - } - - @Override - public MBeanInfo getMBeanInfo() throws Exception { - before(); - try { - return connection.getMBeanInfo(objectName); - } finally { - after(); - } - } - - @Override - public void clean() { - try { - connector.close(); - } catch (IOException e) { - // no-op - } - } - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamic.mbean; + +import javax.annotation.PreDestroy; +import javax.management.Attribute; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanInfo; +import javax.management.MBeanServer; +import javax.management.MBeanServerConnection; +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.lang.management.ManagementFactory; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Need a @PreDestroy method to disconnect the remote host when used in remote mode. + */ +public class DynamicMBeanHandler implements InvocationHandler { + + private final Map<Method, ConnectionInfo> infos = new ConcurrentHashMap<Method, ConnectionInfo>(); + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + final String methodName = method.getName(); + if (method.getDeclaringClass().equals(Object.class) && "toString".equals(methodName)) { + return getClass().getSimpleName() + " Proxy"; + } + if (method.getAnnotation(PreDestroy.class) != null) { + return destroy(); + } + + final ConnectionInfo info = getConnectionInfo(method); + final MBeanInfo infos = info.getMBeanInfo(); + if (methodName.startsWith("set") && methodName.length() > 3 && args != null && args.length == 1 + && (Void.TYPE.equals(method.getReturnType()) || Void.class.equals(method.getReturnType()))) { + final String attributeName = attributeName(infos, methodName, method.getParameterTypes()[0]); + info.setAttribute(new Attribute(attributeName, args[0])); + return null; + } else if (methodName.startsWith("get") && (args == null || args.length == 0) && methodName.length() > 3) { + final String attributeName = attributeName(infos, methodName, method.getReturnType()); + return info.getAttribute(attributeName); + } + // operation + return info.invoke(methodName, args, getSignature(method)); + } + + public Object destroy() { + for (ConnectionInfo info : infos.values()) { + info.clean(); + } + infos.clear(); + return null; + } + + private String[] getSignature(Method method) { + String[] args = new String[method.getParameterTypes().length]; + for (int i = 0; i < method.getParameterTypes().length; i++) { + args[i] = method.getParameterTypes()[i].getName(); + } + return args; // note: null should often work... + } + + private String attributeName(MBeanInfo infos, String methodName, Class<?> type) { + String found = null; + String foundBackUp = null; // without checking the type + final String attributeName = methodName.substring(3, methodName.length()); + final String lowerName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4, methodName.length()); + + for (MBeanAttributeInfo attribute : infos.getAttributes()) { + final String name = attribute.getName(); + if (attributeName.equals(name)) { + foundBackUp = attributeName; + if (attribute.getType().equals(type.getName())) { + found = name; + } + } else if (found == null && ((lowerName.equals(name) && !attributeName.equals(name)) + || lowerName.equalsIgnoreCase(name))) { + foundBackUp = name; + if (attribute.getType().equals(type.getName())) { + found = name; + } + } + } + + if (found == null && foundBackUp == null) { + throw new UnsupportedOperationException("cannot find attribute " + attributeName); + } + + if (found != null) { + return found; + } + return foundBackUp; + } + + private synchronized ConnectionInfo getConnectionInfo(Method method) throws Exception { + if (!infos.containsKey(method)) { + synchronized (infos) { + if (!infos.containsKey(method)) { // double check for synchro + org.superbiz.dynamic.mbean.ObjectName on = method.getAnnotation(org.superbiz.dynamic.mbean.ObjectName.class); + if (on == null) { + Class<?> current = method.getDeclaringClass(); + do { + on = method.getDeclaringClass().getAnnotation(org.superbiz.dynamic.mbean.ObjectName.class); + current = current.getSuperclass(); + } while (on == null && current != null); + if (on == null) { + throw new UnsupportedOperationException("class or method should define the objectName to use for invocation: " + method.toGenericString()); + } + } + final ConnectionInfo info; + if (on.url().isEmpty()) { + info = new LocalConnectionInfo(); + ((LocalConnectionInfo) info).server = ManagementFactory.getPlatformMBeanServer(); // could use an id... + } else { + info = new RemoteConnectionInfo(); + final Map<String, String[]> environment = new HashMap<String, String[]>(); + if (!on.user().isEmpty()) { + environment.put(JMXConnector.CREDENTIALS, new String[]{on.user(), on.password()}); + } + // ((RemoteConnectionInfo) info).connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(on.url()), environment); + ((RemoteConnectionInfo) info).connector = JMXConnectorFactory.connect(new JMXServiceURL(on.url()), environment); + + } + info.objectName = new ObjectName(on.value()); + + infos.put(method, info); + } + } + } + return infos.get(method); + } + + private abstract static class ConnectionInfo { + + protected ObjectName objectName; + + public abstract void setAttribute(Attribute attribute) throws Exception; + + public abstract Object getAttribute(String attribute) throws Exception; + + public abstract Object invoke(String operationName, Object params[], String signature[]) throws Exception; + + public abstract MBeanInfo getMBeanInfo() throws Exception; + + public abstract void clean(); + } + + private static class LocalConnectionInfo extends ConnectionInfo { + + private MBeanServer server; + + @Override + public void setAttribute(Attribute attribute) throws Exception { + server.setAttribute(objectName, attribute); + } + + @Override + public Object getAttribute(String attribute) throws Exception { + return server.getAttribute(objectName, attribute); + } + + @Override + public Object invoke(String operationName, Object[] params, String[] signature) throws Exception { + return server.invoke(objectName, operationName, params, signature); + } + + @Override + public MBeanInfo getMBeanInfo() throws Exception { + return server.getMBeanInfo(objectName); + } + + @Override + public void clean() { + // no-op + } + } + + private static class RemoteConnectionInfo extends ConnectionInfo { + + private JMXConnector connector; + private MBeanServerConnection connection; + + private void before() throws IOException { + connection = connector.getMBeanServerConnection(); + } + + private void after() throws IOException { + // no-op + } + + @Override + public void setAttribute(Attribute attribute) throws Exception { + before(); + connection.setAttribute(objectName, attribute); + after(); + } + + @Override + public Object getAttribute(String attribute) throws Exception { + before(); + try { + return connection.getAttribute(objectName, attribute); + } finally { + after(); + } + } + + @Override + public Object invoke(String operationName, Object[] params, String[] signature) throws Exception { + before(); + try { + return connection.invoke(objectName, operationName, params, signature); + } finally { + after(); + } + } + + @Override + public MBeanInfo getMBeanInfo() throws Exception { + before(); + try { + return connection.getMBeanInfo(objectName); + } finally { + after(); + } + } + + @Override + public void clean() { + try { + connector.close(); + } catch (IOException e) { + // no-op + } + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/ObjectName.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/ObjectName.java b/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/ObjectName.java index 69c4ab1..305db5b 100644 --- a/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/ObjectName.java +++ b/examples/dynamic-proxy-to-access-mbean/src/main/java/org/superbiz/dynamic/mbean/ObjectName.java @@ -1,39 +1,39 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamic.mbean; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Target({TYPE, METHOD}) -@Retention(RUNTIME) -public @interface ObjectName { - - String value(); - - // for remote usage only - String url() default ""; - - String user() default ""; - - String password() default ""; -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamic.mbean; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +public @interface ObjectName { + + String value(); + + // for remote usage only + String url() default ""; + + String user() default ""; + + String password() default ""; +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClient.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClient.java b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClient.java index 57a16cf..ee772f4 100644 --- a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClient.java +++ b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClient.java @@ -1,36 +1,36 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamic.mbean; - -import org.apache.openejb.api.Proxy; - -import javax.ejb.Singleton; - -@Singleton -@Proxy(DynamicMBeanHandler.class) -@ObjectName(DynamicMBeanClient.OBJECT_NAME) -public interface DynamicMBeanClient { - - static final String OBJECT_NAME = "test:group=DynamicMBeanClientTest"; - - int getCounter(); - - void setCounter(int i); - - int length(String aString); -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamic.mbean; + +import org.apache.openejb.api.Proxy; + +import javax.ejb.Singleton; + +@Singleton +@Proxy(DynamicMBeanHandler.class) +@ObjectName(DynamicMBeanClient.OBJECT_NAME) +public interface DynamicMBeanClient { + + static final String OBJECT_NAME = "test:group=DynamicMBeanClientTest"; + + int getCounter(); + + void setCounter(int i); + + int length(String aString); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClientTest.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClientTest.java b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClientTest.java index 81da560..50f4668 100644 --- a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClientTest.java +++ b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicMBeanClientTest.java @@ -1,108 +1,108 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamic.mbean; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.superbiz.dynamic.mbean.simple.Simple; - -import javax.ejb.EJB; -import javax.ejb.embeddable.EJBContainer; -import javax.management.Attribute; -import javax.management.ObjectName; -import java.lang.management.ManagementFactory; - -import static org.junit.Assert.assertEquals; - -public class DynamicMBeanClientTest { - - private static ObjectName objectName; - private static EJBContainer container; - - @EJB - private DynamicMBeanClient localClient; - @EJB - private DynamicRemoteMBeanClient remoteClient; - - @BeforeClass - public static void start() { - container = EJBContainer.createEJBContainer(); - } - - @Before - public void injectAndRegisterMBean() throws Exception { - container.getContext().bind("inject", this); - objectName = new ObjectName(DynamicMBeanClient.OBJECT_NAME); - ManagementFactory.getPlatformMBeanServer().registerMBean(new Simple(), objectName); - } - - @After - public void unregisterMBean() throws Exception { - if (objectName != null) { - ManagementFactory.getPlatformMBeanServer().unregisterMBean(objectName); - } - } - - @Test - public void localGet() throws Exception { - assertEquals(0, localClient.getCounter()); - ManagementFactory.getPlatformMBeanServer().setAttribute(objectName, new Attribute("Counter", 5)); - assertEquals(5, localClient.getCounter()); - } - - @Test - public void localSet() throws Exception { - assertEquals(0, ((Integer) ManagementFactory.getPlatformMBeanServer().getAttribute(objectName, "Counter")).intValue()); - localClient.setCounter(8); - assertEquals(8, ((Integer) ManagementFactory.getPlatformMBeanServer().getAttribute(objectName, "Counter")).intValue()); - } - - @Test - public void localOperation() { - assertEquals(7, localClient.length("openejb")); - } - - @Test - public void remoteGet() throws Exception { - assertEquals(0, remoteClient.getCounter()); - ManagementFactory.getPlatformMBeanServer().setAttribute(objectName, new Attribute("Counter", 5)); - assertEquals(5, remoteClient.getCounter()); - } - - @Test - public void remoteSet() throws Exception { - assertEquals(0, ((Integer) ManagementFactory.getPlatformMBeanServer().getAttribute(objectName, "Counter")).intValue()); - remoteClient.setCounter(8); - assertEquals(8, ((Integer) ManagementFactory.getPlatformMBeanServer().getAttribute(objectName, "Counter")).intValue()); - } - - @Test - public void remoteOperation() { - assertEquals(7, remoteClient.length("openejb")); - } - - @AfterClass - public static void close() { - if (container != null) { - container.close(); - } - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamic.mbean; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.superbiz.dynamic.mbean.simple.Simple; + +import javax.ejb.EJB; +import javax.ejb.embeddable.EJBContainer; +import javax.management.Attribute; +import javax.management.ObjectName; +import java.lang.management.ManagementFactory; + +import static org.junit.Assert.assertEquals; + +public class DynamicMBeanClientTest { + + private static ObjectName objectName; + private static EJBContainer container; + + @EJB + private DynamicMBeanClient localClient; + @EJB + private DynamicRemoteMBeanClient remoteClient; + + @BeforeClass + public static void start() { + container = EJBContainer.createEJBContainer(); + } + + @Before + public void injectAndRegisterMBean() throws Exception { + container.getContext().bind("inject", this); + objectName = new ObjectName(DynamicMBeanClient.OBJECT_NAME); + ManagementFactory.getPlatformMBeanServer().registerMBean(new Simple(), objectName); + } + + @After + public void unregisterMBean() throws Exception { + if (objectName != null) { + ManagementFactory.getPlatformMBeanServer().unregisterMBean(objectName); + } + } + + @Test + public void localGet() throws Exception { + assertEquals(0, localClient.getCounter()); + ManagementFactory.getPlatformMBeanServer().setAttribute(objectName, new Attribute("Counter", 5)); + assertEquals(5, localClient.getCounter()); + } + + @Test + public void localSet() throws Exception { + assertEquals(0, ((Integer) ManagementFactory.getPlatformMBeanServer().getAttribute(objectName, "Counter")).intValue()); + localClient.setCounter(8); + assertEquals(8, ((Integer) ManagementFactory.getPlatformMBeanServer().getAttribute(objectName, "Counter")).intValue()); + } + + @Test + public void localOperation() { + assertEquals(7, localClient.length("openejb")); + } + + @Test + public void remoteGet() throws Exception { + assertEquals(0, remoteClient.getCounter()); + ManagementFactory.getPlatformMBeanServer().setAttribute(objectName, new Attribute("Counter", 5)); + assertEquals(5, remoteClient.getCounter()); + } + + @Test + public void remoteSet() throws Exception { + assertEquals(0, ((Integer) ManagementFactory.getPlatformMBeanServer().getAttribute(objectName, "Counter")).intValue()); + remoteClient.setCounter(8); + assertEquals(8, ((Integer) ManagementFactory.getPlatformMBeanServer().getAttribute(objectName, "Counter")).intValue()); + } + + @Test + public void remoteOperation() { + assertEquals(7, remoteClient.length("openejb")); + } + + @AfterClass + public static void close() { + if (container != null) { + container.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicRemoteMBeanClient.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicRemoteMBeanClient.java b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicRemoteMBeanClient.java index d626517..f93befe 100644 --- a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicRemoteMBeanClient.java +++ b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/DynamicRemoteMBeanClient.java @@ -1,40 +1,40 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamic.mbean; - -import org.apache.openejb.api.Proxy; - -import javax.annotation.PreDestroy; -import javax.ejb.Singleton; - -@Singleton -@Proxy(DynamicMBeanHandler.class) -@ObjectName(value = DynamicRemoteMBeanClient.OBJECT_NAME, url = "service:jmx:rmi:///jndi/rmi://localhost:8243/jmxrmi") -public interface DynamicRemoteMBeanClient { - - static final String OBJECT_NAME = "test:group=DynamicMBeanClientTest"; - - int getCounter(); - - void setCounter(int i); - - int length(String aString); - - @PreDestroy - void clean(); -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamic.mbean; + +import org.apache.openejb.api.Proxy; + +import javax.annotation.PreDestroy; +import javax.ejb.Singleton; + +@Singleton +@Proxy(DynamicMBeanHandler.class) +@ObjectName(value = DynamicRemoteMBeanClient.OBJECT_NAME, url = "service:jmx:rmi:///jndi/rmi://localhost:8243/jmxrmi") +public interface DynamicRemoteMBeanClient { + + static final String OBJECT_NAME = "test:group=DynamicMBeanClientTest"; + + int getCounter(); + + void setCounter(int i); + + int length(String aString); + + @PreDestroy + void clean(); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/Simple.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/Simple.java b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/Simple.java index aaceacf..ff51482 100644 --- a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/Simple.java +++ b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/Simple.java @@ -1,41 +1,41 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamic.mbean.simple; - -public class Simple implements SimpleMBean { - - private int counter = 0; - - @Override - public int length(String s) { - if (s == null) { - return 0; - } - return s.length(); - } - - @Override - public int getCounter() { - return counter; - } - - @Override - public void setCounter(int c) { - counter = c; - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamic.mbean.simple; + +public class Simple implements SimpleMBean { + + private int counter = 0; + + @Override + public int length(String s) { + if (s == null) { + return 0; + } + return s.length(); + } + + @Override + public int getCounter() { + return counter; + } + + @Override + public void setCounter(int c) { + counter = c; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/SimpleMBean.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/SimpleMBean.java b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/SimpleMBean.java index 0b4b8de..95f698e 100644 --- a/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/SimpleMBean.java +++ b/examples/dynamic-proxy-to-access-mbean/src/test/java/org/superbiz/dynamic/mbean/simple/SimpleMBean.java @@ -1,27 +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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.dynamic.mbean.simple; - -public interface SimpleMBean { - - int length(String s); - - int getCounter(); - - void setCounter(int c); -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.dynamic.mbean.simple; + +public interface SimpleMBean { + + int length(String s); + + int getCounter(); + + void setCounter(int c); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ear-testing/README.md ---------------------------------------------------------------------- diff --git a/examples/ear-testing/README.md b/examples/ear-testing/README.md index ab6c2ab..0ca8f8f 100644 --- a/examples/ear-testing/README.md +++ b/examples/ear-testing/README.md @@ -1,212 +1,212 @@ -Title: EAR Testing - -The goal of this example is to demonstrate how maven projects might be organized in a more real world style and how testing with OpenEJB can fit into that structure. - -This example takes the basic moviefun code we us in many of examples and splits it into two modules: - - - `business-logic` - - `business-model` - -As the names imply, we keep our `@Entity` beans in the `business-model` module and our session beans in the `business-logic` model. The tests located and run from the business logic module. - - ear-testing - ear-testing/business-logic - ear-testing/business-logic/pom.xml - ear-testing/business-logic/src/main/java/org/superbiz/logic/Movies.java - ear-testing/business-logic/src/main/java/org/superbiz/logic/MoviesImpl.java - ear-testing/business-logic/src/main/resources - ear-testing/business-logic/src/main/resources/META-INF - ear-testing/business-logic/src/main/resources/META-INF/ejb-jar.xml - ear-testing/business-logic/src/test/java/org/superbiz/logic/MoviesTest.java - ear-testing/business-model - ear-testing/business-model/pom.xml - ear-testing/business-model/src/main/java/org/superbiz/model/Movie.java - ear-testing/business-model/src/main/resources/META-INF/persistence.xml - ear-testing/pom.xml - -# Project configuration - -The parent pom, trimmed to the minimum, looks like so: - - <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - <groupId>org.superbiz</groupId> - <artifactId>myear</artifactId> - <version>1.1.0-SNAPSHOT</version> - - <packaging>pom</packaging> - - <modules> - <module>business-model</module> - <module>business-logic</module> - </modules> - - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.apache.openejb</groupId> - <artifactId>javaee-api</artifactId> - <version>6.0-2</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.8.1</version> - </dependency> - </dependencies> - </dependencyManagement> - </project> - -The `business-model/pom.xml` as follows: - - <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.superbiz</groupId> - <artifactId>myear</artifactId> - <version>1.1.0-SNAPSHOT</version> - </parent> - - <modelVersion>4.0.0</modelVersion> - - <artifactId>business-model</artifactId> - <packaging>jar</packaging> - - <dependencies> - <dependency> - <groupId>org.apache.openejb</groupId> - <artifactId>javaee-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - - </dependencies> - - </project> - -And finally, the `business-logic/pom.xml` which is setup to support embedded testing with OpenEJB: - - <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.superbiz</groupId> - <artifactId>myear</artifactId> - <version>1.1.0-SNAPSHOT</version> - </parent> - - <modelVersion>4.0.0</modelVersion> - - <artifactId>business-logic</artifactId> - <packaging>jar</packaging> - - <dependencies> - <dependency> - <groupId>org.superbiz</groupId> - <artifactId>business-model</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.openejb</groupId> - <artifactId>javaee-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <!-- - The <scope>test</scope> guarantees that non of your runtime - code is dependent on any OpenEJB classes. - --> - <dependency> - <groupId>org.apache.openejb</groupId> - <artifactId>openejb-core</artifactId> - <version>7.0.0-SNAPSHOT</version> - <scope>test</scope> - </dependency> - </dependencies> - </project> - -# TestCode - -The test code is the same as always: - - public class MoviesTest extends TestCase { - - public void test() throws Exception { - Properties p = new Properties(); - p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); - - p.put("openejb.deployments.classpath.ear", "true"); - - p.put("movieDatabase", "new://Resource?type=DataSource"); - p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); - p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); - - p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource"); - p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver"); - p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); - p.put("movieDatabaseUnmanaged.JtaManaged", "false"); - - Context context = new InitialContext(p); - - Movies movies = (Movies) context.lookup("MoviesLocal"); - - movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); - movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); - movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); - - List<Movie> list = movies.getMovies(); - assertEquals("List.size()", 3, list.size()); - - for (Movie movie : list) { - movies.deleteMovie(movie); - } - - assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); - } - } - - -# Running - - - ------------------------------------------------------- - T E S T S - ------------------------------------------------------- - Running org.superbiz.logic.MoviesTest - Apache OpenEJB 7.0.0-SNAPSHOT build: 20111002-04:06 - http://tomee.apache.org/ - INFO - openejb.home = /Users/dblevins/examples/ear-testing/business-logic - INFO - openejb.base = /Users/dblevins/examples/ear-testing/business-logic - INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) - INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) - INFO - Configuring Service(id=movieDatabaseUnmanaged, type=Resource, provider-id=Default JDBC Database) - INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database) - INFO - Found PersistenceModule in classpath: /Users/dblevins/examples/ear-testing/business-model/target/business-model-1.0.jar - INFO - Found EjbModule in classpath: /Users/dblevins/examples/ear-testing/business-logic/target/classes - INFO - Using 'openejb.deployments.classpath.ear=true' - INFO - Beginning load: /Users/dblevins/examples/ear-testing/business-model/target/business-model-1.0.jar - INFO - Beginning load: /Users/dblevins/examples/ear-testing/business-logic/target/classes - INFO - Configuring enterprise application: /Users/dblevins/examples/ear-testing/business-logic/classpath.ear - INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container) - INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container) - INFO - Configuring PersistenceUnit(name=movie-unit) - INFO - Enterprise application "/Users/dblevins/examples/ear-testing/business-logic/classpath.ear" loaded. - INFO - Assembling app: /Users/dblevins/examples/ear-testing/business-logic/classpath.ear - INFO - PersistenceUnit(name=movie-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 415ms - INFO - Jndi(name=MoviesLocal) --> Ejb(deployment-id=Movies) - INFO - Jndi(name=global/classpath.ear/business-logic/Movies!org.superbiz.logic.Movies) --> Ejb(deployment-id=Movies) - INFO - Jndi(name=global/classpath.ear/business-logic/Movies) --> Ejb(deployment-id=Movies) - INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) - INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) - INFO - Deployed Application(path=/Users/dblevins/examples/ear-testing/business-logic/classpath.ear) - Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.393 sec - - Results : - - Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 +Title: EAR Testing + +The goal of this example is to demonstrate how maven projects might be organized in a more real world style and how testing with OpenEJB can fit into that structure. + +This example takes the basic moviefun code we us in many of examples and splits it into two modules: + + - `business-logic` + - `business-model` + +As the names imply, we keep our `@Entity` beans in the `business-model` module and our session beans in the `business-logic` model. The tests located and run from the business logic module. + + ear-testing + ear-testing/business-logic + ear-testing/business-logic/pom.xml + ear-testing/business-logic/src/main/java/org/superbiz/logic/Movies.java + ear-testing/business-logic/src/main/java/org/superbiz/logic/MoviesImpl.java + ear-testing/business-logic/src/main/resources + ear-testing/business-logic/src/main/resources/META-INF + ear-testing/business-logic/src/main/resources/META-INF/ejb-jar.xml + ear-testing/business-logic/src/test/java/org/superbiz/logic/MoviesTest.java + ear-testing/business-model + ear-testing/business-model/pom.xml + ear-testing/business-model/src/main/java/org/superbiz/model/Movie.java + ear-testing/business-model/src/main/resources/META-INF/persistence.xml + ear-testing/pom.xml + +# Project configuration + +The parent pom, trimmed to the minimum, looks like so: + + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.superbiz</groupId> + <artifactId>myear</artifactId> + <version>1.1.0-SNAPSHOT</version> + + <packaging>pom</packaging> + + <modules> + <module>business-model</module> + <module>business-logic</module> + </modules> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>javaee-api</artifactId> + <version>6.0-2</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.8.1</version> + </dependency> + </dependencies> + </dependencyManagement> + </project> + +The `business-model/pom.xml` as follows: + + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.superbiz</groupId> + <artifactId>myear</artifactId> + <version>1.1.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>business-model</artifactId> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>javaee-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + </project> + +And finally, the `business-logic/pom.xml` which is setup to support embedded testing with OpenEJB: + + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.superbiz</groupId> + <artifactId>myear</artifactId> + <version>1.1.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>business-logic</artifactId> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.superbiz</groupId> + <artifactId>business-model</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>javaee-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <!-- + The <scope>test</scope> guarantees that non of your runtime + code is dependent on any OpenEJB classes. + --> + <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>openejb-core</artifactId> + <version>7.0.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + </dependencies> + </project> + +# TestCode + +The test code is the same as always: + + public class MoviesTest extends TestCase { + + public void test() throws Exception { + Properties p = new Properties(); + p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + + p.put("openejb.deployments.classpath.ear", "true"); + + p.put("movieDatabase", "new://Resource?type=DataSource"); + p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); + + p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource"); + p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); + p.put("movieDatabaseUnmanaged.JtaManaged", "false"); + + Context context = new InitialContext(p); + + Movies movies = (Movies) context.lookup("MoviesLocal"); + + movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); + movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); + movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); + + List<Movie> list = movies.getMovies(); + assertEquals("List.size()", 3, list.size()); + + for (Movie movie : list) { + movies.deleteMovie(movie); + } + + assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); + } + } + + +# Running + + + ------------------------------------------------------- + T E S T S + ------------------------------------------------------- + Running org.superbiz.logic.MoviesTest + Apache OpenEJB 7.0.0-SNAPSHOT build: 20111002-04:06 + http://tomee.apache.org/ + INFO - openejb.home = /Users/dblevins/examples/ear-testing/business-logic + INFO - openejb.base = /Users/dblevins/examples/ear-testing/business-logic + INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) + INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) + INFO - Configuring Service(id=movieDatabaseUnmanaged, type=Resource, provider-id=Default JDBC Database) + INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database) + INFO - Found PersistenceModule in classpath: /Users/dblevins/examples/ear-testing/business-model/target/business-model-1.0.jar + INFO - Found EjbModule in classpath: /Users/dblevins/examples/ear-testing/business-logic/target/classes + INFO - Using 'openejb.deployments.classpath.ear=true' + INFO - Beginning load: /Users/dblevins/examples/ear-testing/business-model/target/business-model-1.0.jar + INFO - Beginning load: /Users/dblevins/examples/ear-testing/business-logic/target/classes + INFO - Configuring enterprise application: /Users/dblevins/examples/ear-testing/business-logic/classpath.ear + INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container) + INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container) + INFO - Configuring PersistenceUnit(name=movie-unit) + INFO - Enterprise application "/Users/dblevins/examples/ear-testing/business-logic/classpath.ear" loaded. + INFO - Assembling app: /Users/dblevins/examples/ear-testing/business-logic/classpath.ear + INFO - PersistenceUnit(name=movie-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 415ms + INFO - Jndi(name=MoviesLocal) --> Ejb(deployment-id=Movies) + INFO - Jndi(name=global/classpath.ear/business-logic/Movies!org.superbiz.logic.Movies) --> Ejb(deployment-id=Movies) + INFO - Jndi(name=global/classpath.ear/business-logic/Movies) --> Ejb(deployment-id=Movies) + INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) + INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) + INFO - Deployed Application(path=/Users/dblevins/examples/ear-testing/business-logic/classpath.ear) + Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.393 sec + + Results : + + Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/Movies.java ---------------------------------------------------------------------- diff --git a/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/Movies.java b/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/Movies.java index b5401a0..396e23e 100644 --- a/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/Movies.java +++ b/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/Movies.java @@ -1,33 +1,33 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.superbiz.logic; - -import org.superbiz.model.Movie; - -import java.util.List; - -/** - * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ - */ -public interface Movies { - - void addMovie(Movie movie) throws Exception; - - void deleteMovie(Movie movie) throws Exception; - - List<Movie> getMovies() 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.superbiz.logic; + +import org.superbiz.model.Movie; + +import java.util.List; + +/** + * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public interface Movies { + + void addMovie(Movie movie) throws Exception; + + void deleteMovie(Movie movie) throws Exception; + + List<Movie> getMovies() throws Exception; +}