Search in sources :

Example 1 with Main

use of org.jnp.server.Main in project hibernate-orm by hibernate.

the class JndiRegionFactoryTest method afterStandardServiceRegistryBuilt.

@Override
protected void afterStandardServiceRegistryBuilt(StandardServiceRegistry ssr) {
    if (bindToJndi) {
        try {
            // Create an in-memory jndi
            namingServer = new SingletonNamingServer();
            namingMain = new Main();
            namingMain.setInstallGlobalService(true);
            namingMain.setPort(-1);
            namingMain.start();
            props = new Properties();
            props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
            props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
            final String cfgFileName = (String) ssr.getService(ConfigurationService.class).getSettings().get(InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP);
            manager = new DefaultCacheManager(cfgFileName == null ? InfinispanRegionFactory.DEF_INFINISPAN_CONFIG_RESOURCE : cfgFileName, false);
            Context ctx = new InitialContext(props);
            bind(JNDI_NAME, manager, EmbeddedCacheManager.class, ctx);
        } catch (Exception e) {
            throw new RuntimeException("Failure to set up JNDI", e);
        }
    }
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) SingletonNamingServer(org.jnp.server.SingletonNamingServer) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Properties(java.util.Properties) Main(org.jnp.server.Main) InitialContext(javax.naming.InitialContext) NameNotFoundException(javax.naming.NameNotFoundException)

Example 2 with Main

use of org.jnp.server.Main in project hibernate-orm by hibernate.

the class JBossStandaloneJtaExampleTest method startJndiServer.

private Main startJndiServer() throws Exception {
    // Create an in-memory jndi
    NamingServer namingServer = new NamingServer();
    NamingContext.setLocal(namingServer);
    Main namingMain = new Main();
    namingMain.setInstallGlobalService(true);
    namingMain.setPort(-1);
    namingMain.start();
    return namingMain;
}
Also used : NamingServer(org.jnp.server.NamingServer) Main(org.jnp.server.Main)

Aggregations

Main (org.jnp.server.Main)2 Properties (java.util.Properties)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NameNotFoundException (javax.naming.NameNotFoundException)1 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)1 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)1 NamingServer (org.jnp.server.NamingServer)1 SingletonNamingServer (org.jnp.server.SingletonNamingServer)1