Java Code Examples for javax.naming.spi.NamingManager#getInitialContext()

The following examples show how to use javax.naming.spi.NamingManager#getInitialContext() . 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: JndiContext.java    From jqm with Apache License 2.0 6 votes vote down vote up
/**
 * Will create a JNDI Context and register it as the initial context factory builder
 *
 * @return the context
 * @throws NamingException
 *                             on any issue during initial context factory builder registration
 */
static JndiContext createJndiContext() throws NamingException
{
    try
    {
        if (!NamingManager.hasInitialContextFactoryBuilder())
        {
            JndiContext ctx = new JndiContext();
            NamingManager.setInitialContextFactoryBuilder(ctx);
            return ctx;
        }
        else
        {
            return (JndiContext) NamingManager.getInitialContext(null);
        }
    }
    catch (Exception e)
    {
        jqmlogger.error("Could not create JNDI context: " + e.getMessage());
        NamingException ex = new NamingException("Could not initialize JNDI Context");
        ex.setRootCause(e);
        throw ex;
    }
}
 
Example 2
Source File: InitialContext.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 3
Source File: JmxAgent.java    From jqm with Apache License 2.0 5 votes vote down vote up
static synchronized void registerAgent(int registryPort, int serverPort, String hostname) throws JqmInitError
{
    if (init)
    {
        // The agent is JVM-global, not engine specific, so prevent double start.
        return;
    }

    jqmlogger.trace("registering remote agent");
    try
    {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        JndiContext ctx = (JndiContext) NamingManager.getInitialContext(null);
        ctx.registerRmiContext(LocateRegistry.createRegistry(registryPort));

        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostname + ":" + serverPort + "/jndi/rmi://" + hostname + ":"
                + registryPort + "/jmxrmi");

        JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        cs.start();
        init = true;
        jqmlogger.info("The JMX remote agent was registered. Connection string is " + url);
    }
    catch (Exception e)
    {
        throw new JqmInitError("Could not create remote JMX agent", e);
    }
}
 
Example 4
Source File: InitialContext.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 5
Source File: InitialContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 6
Source File: InitialContext.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 7
Source File: InitialContext.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 8
Source File: InitialContext.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 9
Source File: InitialContext.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 10
Source File: InitialContext.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 11
Source File: InitialContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 12
Source File: InitialContext.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 13
Source File: InitialContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 14
Source File: InitialContext.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 15
Source File: InitialContext.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 16
Source File: InitialContext.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 17
Source File: InitialContext.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}
 
Example 18
Source File: InitialContext.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the initial context by calling
 * <code>NamingManager.getInitialContext()</code>
 * and cache it in defaultInitCtx.
 * Set <code>gotDefault</code> so that we know we've tried this before.
 * @return The non-null cached initial context.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException If a naming exception was encountered.
 */
protected Context getDefaultInitCtx() throws NamingException{
    if (!gotDefault) {
        defaultInitCtx = NamingManager.getInitialContext(myProps);
        gotDefault = true;
    }
    if (defaultInitCtx == null)
        throw new NoInitialContextException();

    return defaultInitCtx;
}