Author: linsun Date: Wed Jul 14 15:52:27 2010 New Revision: 964088 URL: http://svn.apache.org/viewvc?rev=964088&view=rev Log: [message driven service]update service property names to use property names like remote service format
Added: incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSConstants.java (with props) Modified: incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/Activator.java incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml Modified: incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/Activator.java URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/Activator.java?rev=964088&r1=964087&r2=964088&view=diff ============================================================================== --- incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/Activator.java (original) +++ incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/Activator.java Wed Jul 14 15:52:27 2010 @@ -53,6 +53,9 @@ public class Activator implements Bundle System.out.println("aries-mds-impl starts"); Activator.context = context; + // create service tracker for javax.jms.MessageListener + // if we support other message interface, we also need to create the service tracker for those + // or update filter criteria st = createServiceTracker(); st.open(); } Added: incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSConstants.java URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSConstants.java?rev=964088&view=auto ============================================================================== --- incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSConstants.java (added) +++ incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSConstants.java Wed Jul 14 15:52:27 2010 @@ -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.aries.mds.impl; + +public class MDSConstants { + public static final String SERVICE_EXPORT_CONFIG = "service.exported.configs"; + public static final String SERVICE_PID = "service.pid"; + public static final String SERVICE_EXPORT_CONFIG_DEFAULT = "org.apache.aries.message.driven"; + public static final String TRANSACTION_ATTRIBUTE = "transactionAttribute"; + +} Propchange: incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSConstants.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSConstants.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSConstants.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java?rev=964088&r1=964087&r2=964088&view=diff ============================================================================== --- incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java (original) +++ incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java Wed Jul 14 15:52:27 2010 @@ -40,9 +40,11 @@ import org.apache.aries.mds.impl.transac import org.apache.xbean.recipe.ObjectRecipe; import org.apache.xbean.recipe.Option; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + public class MDSContainerImpl implements MDSContainer { private static final Logger LOGGER = LoggerFactory.getLogger(MDSContainerImpl.class); private final ResourceAdapter ra; @@ -52,6 +54,7 @@ public class MDSContainerImpl implements private MessageEndpointFactory endpointFactory; private TransactionPolicyFactory tpf; private Class messageListenerInterface; + private String prefix; public MDSContainerImpl(ResourceAdapter ra, ServiceReference sr, BundleContext bc) { this.ra = ra; @@ -70,24 +73,44 @@ public class MDSContainerImpl implements e.printStackTrace(); } - Object pid = this.sr.getProperty("service.pid"); + Object pid = this.sr.getProperty(MDSConstants.SERVICE_PID); if (pid == null) { - throw new NullPointerException("service.pid has to be specified as a required service property"); + throw new NullPointerException(MDSConstants.SERVICE_PID + " has to be specified as a required service property"); } + Object exportConfig = this.sr.getProperty(MDSConstants.SERVICE_EXPORT_CONFIG); + if (exportConfig == null) { + prefix = MDSConstants.SERVICE_EXPORT_CONFIG_DEFAULT; + } else { + prefix = (String)exportConfig; + } + if (activationSpecClass == null) { throw new NullPointerException( "Unable to load activationSpec class using the classloader of the ra " + ra.toString()); } - activationSpec = createActivationSpec(sr, activationSpecClass); + activationSpec = createActivationSpec(this.sr, activationSpecClass); - Object msgListener = this.sr.getProperty("service.exported.interface"); + Object msgListener = this.sr.getProperty(prefix + ".interface"); + String messageListener = null; if (msgListener == null) { - throw new NullPointerException("service.exported.interface must be specified so that we know the messaging type"); + Object clazz = sr.getProperty(Constants.OBJECTCLASS); + if (clazz != null) { + String[] clazzes = (String[])clazz; + messageListener = clazzes[0]; + System.out.println("**linsun: message listener is " + messageListener); + } + } else { + messageListener = (String)msgListener; + } + + System.out.println("**linsun: message listener is " + messageListener); + if (messageListener == null || messageListener.isEmpty()) { + throw new NullPointerException("Unable to find the message listener interface."); } try { - this.messageListenerInterface = this.getClass().getClassLoader().loadClass((String)msgListener); + this.messageListenerInterface = this.getClass().getClassLoader().loadClass(messageListener); } catch (ClassNotFoundException e) { LOGGER.error("Unable to load the specified message listener interface " + (String)msgListener , e); throw new MDSException(e); @@ -107,7 +130,7 @@ public class MDSContainerImpl implements MessageListener ml = (MessageListener)bc.getService(sr); // create the message endpoint // obtain transaction attribute from service property - String tranAttr = sr.getProperty("transactionAttribute") == null ? null : (String)sr.getProperty("transactionAttribute"); + String tranAttr = sr.getProperty(prefix + "." + MDSConstants.TRANSACTION_ATTRIBUTE) == null ? null : (String)sr.getProperty(prefix + "." + MDSConstants.TRANSACTION_ATTRIBUTE); endpointFactory = new EndpointFactory(this, ml, null, activationSpec, tranAttr, tpf); @@ -148,9 +171,14 @@ public class MDSContainerImpl implements String[] propKeys = reference.getPropertyKeys(); for (String propKey : propKeys) { + if (propKey.startsWith(prefix + "." + MDSConstants.TRANSACTION_ATTRIBUTE)) { + continue; + } // set method property on activation config prop keys - if (propKey.startsWith("ac:")) { - objectRecipe.setMethodProperty(propKey.substring(3), sr.getProperty(propKey)); + if (propKey.startsWith(prefix) && propKey.length() > prefix.length() + 1) { + objectRecipe.setMethodProperty(propKey.substring(prefix.length() + 1), sr.getProperty(propKey)); + } else { + // TODO log - ignore processing the property for activation spec } } Modified: incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=964088&r1=964087&r2=964088&view=diff ============================================================================== --- incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml (original) +++ incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml Wed Jul 14 15:52:27 2010 @@ -25,12 +25,17 @@ <service ref="myMessageDrivenBean" interface="javax.jms.MessageListener"> <service-properties> - <!-- add in activation config properties, starts with prefix ac --> - <entry key="ac:destination" value="Hello.Queue" /> - <entry key="ac:destinationType" value="javax.jms.Queue" /> - <entry key="transactionAttribute" value="Required" /> - <entry key="service.pid" value="org.apache.aries.mds.sample.myMessageDrivenBean" /> - <entry key="service.exported.interface" value="javax.jms.MessageListener" /> + <!-- state the type of configuration used for the remote service --> + <entry key="service.exported.configs" value="org.apache.aries.message.driven" /> + <!-- for the activation config properties add the relevant prefix to the property name --> + <entry key="org.apache.aries.message.driven.destinationType" value="javax.jms.Queue" /> + <entry key="org.apache.aries.message.driven.destination" value="Hello.Queue" /> + <!-- transaction attribute based on the tx:transaction element in blueprint --> + <entry key="org.apache.aries.message.driven.transactionAttribute" value="Required"/> + <!-- assume that the service.pid is the bundle symbolic name followed by the bean id --> + <entry key="service.pid" value="org.apache.aries.mds.sample.myMessageDrivenBean" /> + <!-- optional, only necessary when the service exposes more than 1 interface --> + <!-- <entry key="org.apache.aries.message.driven.interface" value="javax.jms.MessageListener" />--> </service-properties> </service>