Java Code Examples for org.osgi.framework.launch.FrameworkFactory#newFramework()

The following examples show how to use org.osgi.framework.launch.FrameworkFactory#newFramework() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JrtUrlTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Test
public void initFrameWorkAndThenCreateTheUrl() throws Exception {
    Framework framework;
    for (FrameworkFactory ff : ServiceLoader.load(FrameworkFactory.class)) {
        Map<String, String> config = new HashMap<String, String>();
        framework = ff.newFramework(config);
        framework.init();
        framework.start();
        break;
    }

    URL test = new URL("jrt://java.compiler/");
    assertEquals("jrt", test.getProtocol());
}
 
Example 2
Source File: CarbonServer.java    From carbon-kernel with Apache License 2.0 5 votes vote down vote up
/**
 * Starts a Carbon server instance. This method returns only after the server instance stops completely.
 *
 * @throws Exception if error occurred
 */
public void start() throws Exception {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "Starting Carbon server instance.");
    }

    // Sets the server start time.
    System.setProperty(CARBON_START_TIME, Long.toString(System.currentTimeMillis()));

    try {
        // Creates an OSGi framework instance.
        ClassLoader fwkClassLoader = createOSGiFwkClassLoader();
        FrameworkFactory fwkFactory = loadOSGiFwkFactory(fwkClassLoader);
        framework = fwkFactory.newFramework(config.getProperties());

        setServerCurrentStatus(ServerStatus.STARTING);
        // Notify Carbon server start.
        dispatchEvent(CarbonServerEvent.STARTING);

        // Initialize and start OSGi framework.
        initAndStartOSGiFramework(framework);

        // Loads initial bundles listed in the launch.properties file.
        loadInitialBundles(framework.getBundleContext());

        setServerCurrentStatus(ServerStatus.STARTED);
        // This thread waits until the OSGi framework comes to a complete shutdown.
        waitForServerStop(framework);

        setServerCurrentStatus(ServerStatus.STOPPING);
        // Notify Carbon server shutdown.
        dispatchEvent(CarbonServerEvent.STOPPING);

    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
Example 3
Source File: Starter.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public void start ( final String[] args ) throws Exception
{
    if ( this.started )
    {
        return;
    }
    this.started = true;

    this.debug = Boolean.getBoolean ( "org.eclipse.scada.utils.osgi.daemon.debug" ); //$NON-NLS-1$
    if ( this.debug )
    {
        this.logger = new Formatter ( System.out );
    }

    final ServiceLoader<FrameworkFactory> loader = ServiceLoader.load ( FrameworkFactory.class );
    final Iterator<FrameworkFactory> i = loader.iterator ();
    if ( !i.hasNext () )
    {
        throw new IllegalStateException ( "No FrameworkFactory found!" );
    }

    final FrameworkFactory factory = i.next ();

    this.properties = new HashMap<String, String> ();

    for ( final String arg : args )
    {
        final String[] toks = arg.split ( "=", 2 );
        if ( toks.length >= 2 )
        {
            this.properties.put ( toks[0], toks[1] );
        }
        else
        {
            this.properties.put ( toks[0], null );
        }
    }

    this.properties.put ( Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "4" );

    this.framework = factory.newFramework ( this.properties );

    this.framework.init ();

    try
    {
        loadStartBundles ( this.framework, this.properties );
    }
    catch ( final Exception e )
    {
        this.framework.stop ();
        throw e;
    }

    this.framework.start ();
}