示例#1
0
  protected void createSpringParentRegistry(
      MuleContext muleContext, Registry registry, ConfigResource[] all) {
    Resource[] servletContextResources = new Resource[all.length];
    for (int i = 0; i < all.length; i++) {
      servletContextResources[i] =
          new ServletContextOrClassPathResource(context, all[i].getResourceName());
    }

    parentContext = loadParentContext(context);

    try {
      if (parentContext != null) {
        new MuleApplicationContext(muleContext, registry, servletContextResources, parentContext);
      } else {
        new MuleApplicationContext(muleContext, registry, servletContextResources);
      }
    } catch (BeansException e) {
      // If creation of MuleApplicationContext fails, remove
      // TransientRegistry->SpringRegistry parent relationship
      registry.setParent(null);
      throw e;
    } catch (IOException e) {
      registry.setParent(null);
      throw new ApplicationContextException("Failed to load config resource", e);
    }
  }
  public BlockingQueue getQueue(String key, int capacity) throws Exception {

    BlockingQueue queue = null;

    if (HazelcastManager.hasInstance()) {
      logger.info("Mule clustering is enabled; using Hazelcast queue");
      HazelcastInstance instance = HazelcastManager.getInstance().getHazelcastInstance();
      queue = instance.getQueue(key);
    } else {
      logger.info("Mule clustering is disabled; using local queue");
      queue = registry.lookupObject(key);
      if (queue == null) {
        queue = new ArrayBlockingQueue<Long>(capacity);
        registry.registerObject(key, queue);
      }
    }

    return queue;
  }
示例#3
0
  protected void doConfigure(MuleContext muleContext) throws Exception {
    Registry registry;

    if (parentContext != null) {
      if (appContext instanceof ConfigurableApplicationContext) {
        registry = new SpringRegistry((ConfigurableApplicationContext) appContext, parentContext);
      } else {
        throw new ConfigurationException(
            MessageFactory.createStaticMessage(
                "Cannot set a parent context if the ApplicationContext does not implement ConfigurableApplicationContext"));
      }
    } else {
      registry = new SpringRegistry(appContext);
    }

    // Note: The SpringRegistry must be created before applicationContext.refresh() gets called
    // because
    // some beans may try to look up other beans via the Registry during preInstantiateSingletons().
    muleContext.addRegistry(registry);
    registry.initialise();
  }
示例#4
0
 public void unconfigure(MuleContext muleContext) {
   registry.dispose();
   muleContext.removeRegistry(registry);
   registry = null;
   configured = false;
 }