當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。