Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
JOnAS: Java(TM) Open Application Server Copyright (C) 2008-2010 Bull S.A.S. Contact: jonas-team@ow2.org This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------- $Id: CamelWrapper.java 20572 2010-11-09 08:55:27Z alitokmen $ --------------------------------------------------------------------------
 
 package org.ow2.jonas.camel.wrapper;
 
 import java.util.List;
 import java.util.Set;
 
 
Camel wrapper. A camel context is wrapped here.

Author(s):
Guillaume Renault
 
 public class CamelWrapper implements ICamelWrapper {

    
Logger.
 
     private final Log logger = LogFactory.getLog(this.getClass());

    
Main camel instance.
 
     private CamelContext camel = null;

    
Name of the camel context.
 
     private String name;

    
The camel registry wrapper.
 
     private RegistryWrapper registryWrapper;

    
Constructor, creates a new Camel context.

Parameters:
bundleContext Bundle context to use.
 
     public CamelWrapper(final BundleContext bundleContext) {
         final DefaultCamelContext ctx = new OsgiDefaultCamelContext(bundleContext);
         OSGiRegistry osgiRegistry = new OSGiRegistry(bundleContext);
         ctx.setRegistry(osgiRegistry);
         // for compatibility with previous registry only, routes beginning
         // with registry: should be associate with Camel's RefComponent
         ctx.addComponent("registry"new RefComponent());
         // create the wrapper
         this. = new RegistryWrapper();
         // Create the registry and assign the context to it.
         this. = ctx;
     }

    
Gets the camel context name.

Returns:
the camel context name.
 
    public String getCamelContextName() {
        return this..getName();
    }

    
Main method.
    public void run() throws Exception {
        while (true) {
            MBeanServer mBeanServer = null;
            ObjectName j2eeServer = null;
            for (final Object o : MBeanServerFactory.findMBeanServer(null)) {
                final MBeanServer currentServer = (MBeanServero;
                final Set<?> j2eeServerNames = currentServer.queryNames(new ObjectName("*:j2eeType=J2EEServer,*"), null);
                if (j2eeServerNames.size() > 0) {
                    j2eeServer = (ObjectNamej2eeServerNames.iterator().next();
                    mBeanServer = currentServer;
                    break;
                }
            }
            if (mBeanServer == null) {
                this..info("CamelWrapper is running outside a J2EEServer");
                break;
            }
            final String state = mBeanServer.getAttribute(j2eeServer"state").toString();
            if (state.contains("running")) {
                // Server is running :)
                break;
            } else if (!state.contains("starting")) {
                throw new Exception("Server state is " + state + ", canceling context creation");
            }
            // Server not started, wait a bit and try again
            this..debug("The J2EEServer hosting CamelWrapper is still starting, waiting...");
            Thread.sleep(100);
        }
        this..start();
    }

    
Stop the camel context.
    public void stopContext() throws Exception {
        this..stop();
    }

    
Add a route.

Parameters:
builder the route to add.
    public void addRoutes(final RouteBuilder builderthrows Exception {
        this..debug("Adding a route to the context");
        this..addRoutes(builder);
    }

    

Returns:
the list of deployed routes on the camel context.
        return this..getRouteDefinitions();
    }

    
Get a producer template for the camel context.

Returns:
a producer for the camel context.
        return this..createProducerTemplate();
    }

    
Add a component on the given camel context.

Parameters:
componentName the component name.
component the component.
    public void addComponent(final String componentNamefinal Component component) {
        component.setCamelContext(this.);
        this..addComponent(componentNamecomponent);
    }

    
Get the name of the camel context.

Returns:
the name of the camel context.
    public String getName() {
        return this.;
    }

    
Set the name of the camel context.

Parameters:
name the name of the camel context.
    public void setName(final String name) {
        this. = name;
    }

    

Returns:
the wrapped camel instance.
    public CamelContext getCamelContext() {
        return this.;
    }
    public void addToTheRegistry(final InputStream inputStreamthrows Exception {
        this..addToTheRegistry(inputStream);
    }
    public void removeFromTheRegistry(final InputStream inputStream) {
        this..removeFromTheRegistry(inputStream);
    }
        return this.;
    }
New to GrepCode? Check out our FAQ X