当前位置: 首页>>代码示例>>Java>>正文


Java Context.close方法代码示例

本文整理汇总了Java中javax.naming.Context.close方法的典型用法代码示例。如果您正苦于以下问题:Java Context.close方法的具体用法?Java Context.close怎么用?Java Context.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.naming.Context的用法示例。


在下文中一共展示了Context.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import javax.naming.Context; //导入方法依赖的package包/类
private void init() {

        if (!isAlwaysLookup()) {
            Context ctx = null;
            try {
                ctx = (props != null) ? new InitialContext(props) : new InitialContext(); 

                datasource = (DataSource) ctx.lookup(url);
            } catch (Exception e) {
                getLog().error(
                        "Error looking up datasource: " + e.getMessage(), e);
            } finally {
                if (ctx != null) {
                    try { ctx.close(); } catch(Exception ignore) {}
                }
            }
        }
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:JNDIConnectionProvider.java

示例2: createJMSProviderObject

import javax.naming.Context; //导入方法依赖的package包/类
/**
 * Creates an object using qpid/amq initial context factory.
 *
 * @param className can be any of the qpid/amq supported JNDI properties:
 *                  connectionFactory, queue, topic, destination.
 * @param address   of the connection or node to create.
 */
protected Object createJMSProviderObject(String className, String address) {
    /* Name of the object is the same as class of the object */
    String name = className;
    properties.setProperty(className + "." + name, address);

    Object jmsProviderObject = null;
    try {
        Context context = new InitialContext(properties);
        jmsProviderObject = context.lookup(name);
        context.close();
    } catch (NamingException e) {
        e.printStackTrace();
    }
    return jmsProviderObject;
}
 
开发者ID:rh-messaging,项目名称:cli-java,代码行数:23,代码来源:AocConnectionManager.java

示例3: createJMSProviderObject

import javax.naming.Context; //导入方法依赖的package包/类
/**
 * Creates an object using qpid/amq initial context factory.
 *
 * @param className can be any of the qpid/amq supported JNDI properties:
 *                  connectionFactory, queue, topic, destination.
 * @param address   of the connection or node to create.
 */
protected Object createJMSProviderObject(String className, String address) {
    final String initialContext = AMQ_INITIAL_CONTEXT;
    Properties properties = new Properties();
    /* Name of the object is the same as class of the object */
    String name = className;
    properties.setProperty("java.naming.factory.initial", initialContext);
    properties.setProperty(className + "." + name, address);

    Object jmsProviderObject = null;
    try {
        Context context = new InitialContext(properties);
        jmsProviderObject = context.lookup(name);
        context.close();
    } catch (NamingException e) {
        e.printStackTrace();
    }
    return jmsProviderObject;
}
 
开发者ID:rh-messaging,项目名称:cli-java,代码行数:26,代码来源:AacConnectionManager.java

示例4: closeJNDI

import javax.naming.Context; //导入方法依赖的package包/类
void closeJNDI(Context context) {
    if (context != null) {
        try {
            context.close();
        } catch (Exception e) {
            logger.logError(Log4jLogger.SYSTEM_LOG, e,
                    LogMessageIdentifier.ERROR_CLOSE_RESOURCE_FAILED);
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:TaskQueueServiceBean.java

示例5: releaseContext

import javax.naming.Context; //导入方法依赖的package包/类
/**
 * Release a JNDI context as obtained from {@link #getContext()}.
 * @param ctx the JNDI context to release (may be {@code null})
 * @see #getContext
 */
public void releaseContext(Context ctx) {
	if (ctx != null) {
		try {
			ctx.close();
		}
		catch (NamingException ex) {
			logger.debug("Could not close JNDI InitialContext", ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:JndiTemplate.java

示例6: getConnection

import javax.naming.Context; //导入方法依赖的package包/类
public Connection getConnection() throws SQLException {
    Context ctx = null;
    try {
        Object ds = this.datasource;

        if (ds == null || isAlwaysLookup()) {
            ctx = (props != null) ? new InitialContext(props): new InitialContext(); 

            ds = ctx.lookup(url);
            if (!isAlwaysLookup()) {
                this.datasource = ds;
            }
        }

        if (ds == null) {
            throw new SQLException( "There is no object at the JNDI URL '" + url + "'");
        }

        if (ds instanceof XADataSource) {
            return (((XADataSource) ds).getXAConnection().getConnection());
        } else if (ds instanceof DataSource) { 
            return ((DataSource) ds).getConnection();
        } else {
            throw new SQLException("Object at JNDI URL '" + url + "' is not a DataSource.");
        }
    } catch (Exception e) {
        this.datasource = null;
        throw new SQLException(
                "Could not retrieve datasource via JNDI url '" + url + "' "
                        + e.getClass().getName() + ": " + e.getMessage());
    } finally {
        if (ctx != null) {
            try { ctx.close(); } catch(Exception ignore) {}
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:JNDIConnectionProvider.java

示例7: testWith

import javax.naming.Context; //导入方法依赖的package包/类
private static void testWith(String appletProperty) throws NamingException {
    Hashtable<Object, Object> env = new Hashtable<>();
    // Deliberately put java.lang.Object rather than java.applet.Applet
    // if an applet was used we would see a ClassCastException down there
    env.put(appletProperty, new Object());
    // It's ok to instantiate InitialContext with no parameters
    // and be unaware of it right until you try to use it
    Context ctx = new InitialContext(env);
    boolean threw = true;
    try {
        ctx.lookup("whatever");
        threw = false;
    } catch (NoInitialContextException e) {
        String m = e.getMessage();
        if (m == null || m.contains("applet"))
            throw new RuntimeException("The exception message is incorrect", e);
    } catch (Throwable t) {
        throw new RuntimeException(
                "The test was supposed to catch NoInitialContextException" +
                        " here, but caught: " + t.getClass().getName(), t);
    } finally {
        ctx.close();
    }

    if (!threw)
        throw new RuntimeException("The test was supposed to catch NoInitialContextException here");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:AppletIsNotUsed.java

示例8: lookupRemoteStatelessHello

import javax.naming.Context; //导入方法依赖的package包/类
/**
 * Looks up and returns the proxy to remote stateless calculator bean
 *
 * @return
 * @throws NamingException
 */
private static RemoteHello lookupRemoteStatelessHello() throws NamingException {
    final Hashtable<String, Object> jndiProperties = new Hashtable<String, Object>();
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    final Context context = new InitialContext(jndiProperties);
    try {
        // The app name is the application name of the deployed EJBs. This is typically the ear name
        // without the .ear suffix. However, the application name could be overridden in the application.xml of the
        // EJB deployment on the server.
        // Since we haven't deployed the application as a .ear, the app name for us will be an empty string
        final String appName = "";
        // This is the module name of the deployed EJBs on the server. This is typically the jar name of the
        // EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
        // In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
        // jboss-as-ejb-remote-app
        final String moduleName = "ejb-module";
        // AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
        // our EJB deployment, so this is an empty string
        final String distinctName = "";
        // The EJB name which by default is the simple class name of the bean implementation class
        final String beanName = HelloBean.class.getSimpleName();
        // the remote view fully qualified class name
        final String viewClassName = RemoteHello.class.getName();
        // let's do the lookup
        String lookupKey = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName;
        System.out.println("Lookup for remote EJB bean: " + lookupKey);
        return (RemoteHello) context.lookup(lookupKey);
    } finally {
        context.close();
    }

}
 
开发者ID:mposolda,项目名称:keycloak-remote-ejb,代码行数:38,代码来源:RemoteEjbClient.java

示例9: run

import javax.naming.Context; //导入方法依赖的package包/类
@Override
public void run() {
    status = 1;
    taskDao.setStarted(taskId);
    taskDao.setStatus(taskId, TaskStatus.IN_PROGRESS);

    Context context = null;
    try {
        JmdTask task = taskDao.getTask(taskId);

        if (!task.getStopFlag()) {
            context = new javax.naming.InitialContext();
            Object target = context.lookup(task.getActor());

            LOGGER.fine(MessageFormat.format("Task with id {0} will be executed by actor {1}.",
                    taskId, task.getActor()));

            Method method = target.getClass().getDeclaredMethod("executeTask", Long.class, String.class);
            method.invoke(target, taskId, task.getCreator());
        }

        task = taskDao.getTask(taskId);
        if (task.getStopFlag() || task.getInterruptFlag()) {
            if (task.getStopFlag()) {
                new TaskUtil().setStopped(taskDao, taskId);
            } else {
                new TaskUtil().setInterrupted(taskDao, taskId);
            }
        } else {
            new TaskUtil().setFinished(taskDao, taskId);
        }
    } catch (Exception e) {
        LOGGER.severe(MessageFormat.format("Task [id {0}] run failed!", taskId));
        LOGGER.log(Level.SEVERE, e.toString(), e);
        new TaskUtil().setFailed(taskDao, taskId, e, taskAppService.getTmpDir());
    } finally {
        if (context != null) {
            try {
                context.close();
            } catch (NamingException ex) {
            }
        }
        status = 2;
    }
}
 
开发者ID:jmd-stuff,项目名称:task-app,代码行数:46,代码来源:TaskRunner.java


注:本文中的javax.naming.Context.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。