1 Reply Latest reply: Jun 27, 2012 3:25 AM by 665356 RSS

    Probelm creating Adapter stage programmatically

    938644
      Hi
      I want to create ( or get ) all the stages in a certain application .
      I try to do this :

           String instanceName="om.bea.wlevs:Name=fxMarketAsia,Type=Adapter,Application=MyCEPPrj";
      ObjectName currObject = ObjectName.getInstance(instanceName);
      ....
      The thind is , when i do this with other stages , there are no problems , and everything is working fine .

      With stages of kind 'Adapter' I get the error from the server :
      <Connection for fxMarketAsia has raised exception java.io.IOException: Connection reset by peer., possibly closed by peer>

      Any Idea ?

      Thanks.
        • 1. Re: Probelm creating Adapter stage programmatically
          665356
          You would probably do better to walk the Spring bean tree internally. Here is a test we have that does this:

          package com.bea.wlevs.test.stagewalker;

          import java.util.List;

          import com.bea.core.servicehelper.ServiceHelper;
          import com.bea.wlevs.deployment.spi.DeploymentListener;
          import com.bea.wlevs.deployment.spi.DeploymentEventMulticaster;
          import com.bea.wlevs.deployment.spi.Deployment;
          import com.bea.wlevs.ede.api.DisposableBean;
          import org.osgi.framework.BundleContext;
          import org.springframework.beans.factory.BeanDefinitionStoreException;
          import org.springframework.beans.factory.InitializingBean;
          import org.springframework.beans.factory.config.BeanDefinition;
          import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
          import org.springframework.osgi.context.BundleContextAware;
          import org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext;

          /**
          * @author Andy Piper
          */
          public class StageWalker implements InitializingBean, DisposableBean, DeploymentListener,
          BundleContextAware {

          private DeploymentEventMulticaster deployer;
          private List<ConfigurableOsgiBundleApplicationContext> deployedContexts;

          public DeploymentEventMulticaster getDeployer() {
          return deployer;
          }

          public void setDeployer(DeploymentEventMulticaster deployer) {
          this.deployer = deployer;
          }

          public void setDeployedContexts(List<ConfigurableOsgiBundleApplicationContext> contexts) {
          this.deployedContexts = contexts;
          }

          public void afterPropertiesSet() throws Exception {
          deployer.addDeploymentListener(this);
          log("StageWalker created");
          /*
          for (ConfigurableOsgiBundleApplicationContext context : deployedContexts) {
          String name = context.getBundle().getSymbolicName();
          log("Application [" + name + "] was deployed, dumping stage tree");
          walkStageTree(context);
          }
          */
          }

          public void onDeploymentEvent(DeploymentEventMulticaster.DeploymentEvent event, String name, Deployment.DeploymentState state) {
          log("Deployment event [" + name + "]");
          // Make sure the Spring context is available
          try {
          ConfigurableOsgiBundleApplicationContext context =
          (ConfigurableOsgiBundleApplicationContext)
          new ServiceHelper(bundleContext).registerDependencyWithFilter(
          "(&(objectClass=" + ConfigurableOsgiBundleApplicationContext.class.getName() +
          ") (org.springframework.context.service.name=" + name + "))").waitForServiceObject(10000);
          walkStageTree(context);
          /*
          for (ConfigurableOsgiBundleApplicationContext context : deployedContexts) {
          if (context.getBundle().getSymbolicName().equals(name)) {
          log("Application [" + name + "] was deployed, dumping stage tree");
          walkStageTree(context);
          }
          }
          */

          } catch (Exception e) {
          throw new IllegalArgumentException(e);
          }

          }

          private void walkStageTree(ConfigurableOsgiBundleApplicationContext context) {
          PropertyValueResolver valueResolver = new StageResolvingStringValueResolver();
          BeanDefinitionPropertyVisitor visitor = new BeanDefinitionPropertyVisitor(valueResolver);
          ConfigurableListableBeanFactory beanFactoryToProcess = context.getBeanFactory();

          String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
          for (int i = 0; i < beanNames.length; i++) {
          BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames);
          try {
          visitor.visitBeanDefinition(beanNames[i], bd);
          }
          catch (BeanDefinitionStoreException ex) {
          throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], ex.getMessage());
          }
          }

          // New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
          beanFactoryToProcess.resolveAliases(valueResolver);
          }

          public void destroy() throws Exception {
          deployer.removeDeploymentListener(this);
          }

          public void log(String msg) {
          System.out.println(msg);
          }

          private BundleContext bundleContext;

          public void setBundleContext(BundleContext bundleContext) {
          this.bundleContext = bundleContext;
          }

          private class StageResolvingStringValueResolver implements PropertyValueResolver {
          private int indent = 0;

          public String resolveStringValue(String name, String strVal) {
          log(pad(indent) + name + "=" + strVal);
          return strVal;
          }

          public void pushElement(String name, String type) {
          log(pad(indent) + type + " [" + name + "]");
          indent++;
          }

          public void popElement(String name, String type) {
          indent--;
          }

          public String resolveStringValue(String strVal) {
          return strVal;
          }

          String pad(int padn) {
          StringBuffer b = new StringBuffer();
          for (int i = 0; i < padn; i++) {
          b.append(" ");
          }
          return b.toString();
          }
          }
          }