Search in sources :

Example 16 with JmsHost

use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.

the class ActiveJmsResourceAdapter method setLifecycleProperties.

/**
 * Set MQ4.0 RA lifecycle properties
 */
private void setLifecycleProperties() throws Exception, ConnectorRuntimeException {
    // ConfigContext ctx = ApplicationServer.getServerContext().getConfigContext();
    // If PE:
    // EMBEDDED/LOCAL goto jms-service, get defaultjmshost info and set
    // accordingly
    // if EE:
    // EMBEDDED/LOCAL get this instance and cluster name, search for a
    // jms-host wth this this name in jms-service gets its proeprties
    // and set
    // @siva As of now use default JMS host. As soon as changes for modifying EE
    // cluster to LOCAL is brought in, change this to use system properties
    // for EE to get port, host, adminusername, adminpassword.
    // JmsService jmsService = ServerBeansFactory.getJmsServiceBean(ctx);
    String defaultJmsHost = getJmsService().getDefaultJmsHost();
    if (_logger.isLoggable(Level.FINE))
        logFine("Default JMS Host :: " + defaultJmsHost);
    JmsHost jmsHost = getJmsHost();
    if (jmsHost != null) {
        // todo: && jmsHost.isEnabled()) {
        JavaConfig javaConfig = (JavaConfig) Globals.get(JavaConfig.class);
        ;
        String java_home = javaConfig.getJavaHome();
        // Get broker type from JMS Service.
        // String brokerType = jmsService.getType();
        /*
             * XXX: adjust the brokertype for the new DIRECT mode in 4.1
             * uncomment the line below once we have an MQ integration
             * that has DIRECT mode support
             */
        String brokerType = adjustForDirectMode(getJmsService().getType());
        String brokerPort = jmsHost.getPort();
        brkrPort = brokerPort;
        String adminUserName = jmsHost.getAdminUserName();
        String adminPassword = JmsRaUtil.getUnAliasedPwd(jmsHost.getAdminPassword());
        List jmsHostProps = getJmsService().getProperty();
        String username = null;
        String password = null;
        if (jmsHostProps != null) {
            for (int i = 0; i < jmsHostProps.size(); i++) {
                Property jmsProp = (Property) jmsHostProps.get(i);
                String propName = jmsProp.getName();
                String propValue = jmsProp.getValue();
                if ("user-name".equals(propName)) {
                    username = propValue;
                } else if ("password".equals(propName)) {
                    password = propValue;
                }
            // Add more properties as and when you want.
            }
        }
        if (_logger.isLoggable(Level.FINE))
            logFine("Broker UserName = " + username);
        createMQVarDirectoryIfNecessary();
        String brokerVarDir = getMQVarDir();
        String tmpString = getJmsService().getStartArgs();
        if (tmpString == null) {
            tmpString = "";
        }
        String brokerArgs = tmpString;
        // by adding the start-args for the broker configuration
        if (!tmpString.contains("-jrehome") && availableJDKForStartArgs()) {
            brokerArgs = brokerArgs + buildStartArgsForJREHome(java_home);
        }
        // XX: Extract the information from the optional properties.
        List jmsProperties = getJmsService().getProperty();
        List jmsHostProperties = jmsHost.getProperty();
        Properties jmsServiceProp = listToProperties(jmsProperties);
        Properties jmsHostProp = listToProperties(jmsHostProperties);
        jmsServiceProp.putAll(jmsHostProp);
        if (jmsServiceProp.size() > 0) {
            if (dbProps == null)
                dbProps = new Properties();
            dbProps.putAll(jmsServiceProp);
        }
        /*
	   String jmsPropertiesStr =  null ;
	   if(jmsServiceProp.size() > 0)
	   {
	   try{
	   	StringWriter writer = new StringWriter();
	   	jmsServiceProp.store(writer, "Properties defined in JMSService and JMSHost");
	   	jmsPropertiesStr =  writer.toString();
	   }catch(Exception e){}//todo: log error;
	   } */
        String brokerHomeDir = getBrokerHomeDir();
        String brokerLibDir = getBrokerLibDir();
        if (brokerInstanceName == null) {
            brokerInstanceName = getBrokerInstanceName(getJmsService());
        }
        long brokerTimeOut = getBrokerTimeOut(getJmsService());
        // Need to set the following properties
        // BrokerType, BrokerInstanceName, BrokerPort,
        // BrokerArgs, BrokerHomeDir, BrokerVarDir, BrokerStartTimeout
        // adminUserName, adminPassword
        ConnectorDescriptor cd = getDescriptor();
        /*if(jmsPropertiesStr != null){
            	ConnectorConfigProperty  envProp = new ConnectorConfigProperty  (
                    "BrokerProps", jmsPropertiesStr, "Broker Props", "java.lang.String");
            	setProperty(cd, envProp);
	    }  */
        ConnectorConfigProperty envProp1 = new ConnectorConfigProperty(BROKERTYPE, brokerType, "Broker Type", "java.lang.String");
        setProperty(cd, envProp1);
        ConnectorConfigProperty envProp2 = new ConnectorConfigProperty(BROKERINSTANCENAME, brokerInstanceName, "Broker Instance Name", "java.lang.String");
        setProperty(cd, envProp2);
        ConnectorConfigProperty envProp3 = new ConnectorConfigProperty(BROKERPORT, brokerPort, "Broker Port", "java.lang.String");
        setProperty(cd, envProp3);
        ConnectorConfigProperty envProp4 = new ConnectorConfigProperty(BROKERARGS, brokerArgs, "Broker Args", "java.lang.String");
        setProperty(cd, envProp4);
        ConnectorConfigProperty envProp5 = new ConnectorConfigProperty(BROKERHOMEDIR, brokerHomeDir, "Broker Home Dir", "java.lang.String");
        setProperty(cd, envProp5);
        ConnectorConfigProperty envProp14 = new ConnectorConfigProperty(BROKERLIBDIR, brokerLibDir, "Broker Lib Dir", "java.lang.String");
        setProperty(cd, envProp14);
        ConnectorConfigProperty envProp6 = new ConnectorConfigProperty(BROKERJAVADIR, java_home, "Broker Java Dir", "java.lang.String");
        setProperty(cd, envProp6);
        ConnectorConfigProperty envProp7 = new ConnectorConfigProperty(BROKERVARDIR, brokerVarDir, "Broker Var Dir", "java.lang.String");
        setProperty(cd, envProp7);
        ConnectorConfigProperty envProp8 = new ConnectorConfigProperty(BROKERSTARTTIMEOUT, "" + brokerTimeOut, "Broker Start Timeout", "java.lang.String");
        setProperty(cd, envProp8);
        ConnectorConfigProperty envProp9 = new ConnectorConfigProperty(ADMINUSERNAME, adminUserName, "Broker admin username", "java.lang.String");
        setProperty(cd, envProp9);
        ConnectorConfigProperty envProp10 = new ConnectorConfigProperty(ADMINPASSWORD, adminPassword, "Broker admin password", "java.lang.String");
        setProperty(cd, envProp10);
        ConnectorConfigProperty envProp11 = new ConnectorConfigProperty(USERNAME, username, "Broker username", "java.lang.String");
        setProperty(cd, envProp11);
        ConnectorConfigProperty envProp12 = new ConnectorConfigProperty(PASSWORD, password, "Broker password", "java.lang.String");
        setProperty(cd, envProp12);
    /* //set adminpassfile
            if (!getJmsService().getType().equals(REMOTE)) {
                //For LOCAL and EMBEDDED, we pass in the admin pass file path
                //containing the MQ admin password to enable authenticated
                //startup of the broker.
                String adminPassFilePath = getAdminPassFilePath(adminPassword);
                if (adminPassFilePath != null) {
                    ConnectorConfigProperty  envProp13 = new ConnectorConfigProperty  (
                            ADMINPASSFILE , adminPassFilePath ,
                            "Broker admin password", "java.lang.String");
                    setProperty(cd, envProp13);
                }
            }*/
    }
// Optional
// BrokerBindAddress, RmiRegistryPort
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) Properties(java.util.Properties) Property(org.jvnet.hk2.config.types.Property) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty)

Example 17 with JmsHost

use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.

the class ActiveJmsResourceAdapter method getJmsHost.

protected JmsHost getJmsHost() {
    String defaultJmsHost = getJmsService().getDefaultJmsHost();
    if (defaultJmsHost == null || defaultJmsHost.equals("")) {
        return (JmsHost) Globals.get(JmsHost.class);
    }
    List jmsHostsList = getJmsService().getJmsHost();
    if (jmsHostsList == null || jmsHostsList.size() == 0) {
        return (JmsHost) Globals.get(JmsHost.class);
    }
    JmsHost jmsHost = null;
    for (int i = 0; i < jmsHostsList.size(); i++) {
        JmsHost tmpJmsHost = (JmsHost) jmsHostsList.get(i);
        if (tmpJmsHost != null && tmpJmsHost.getName().equals(defaultJmsHost)) {
            jmsHost = tmpJmsHost;
            break;
        }
    }
    if (jmsHost == null) {
        jmsHost = (JmsHost) jmsHostsList.get(0);
    }
    return jmsHost;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

Example 18 with JmsHost

use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.

the class MQAddressList method getResolvedJmsHostForStandaloneServerInstance.

// Used to get resolved local JmsHost for a standalone server instance
private JmsHost getResolvedJmsHostForStandaloneServerInstance(String serverName) throws Exception {
    if (logger.isLoggable(Level.FINE))
        logFine(" getresolved " + serverName);
    // ConfigContext con =  getAdminConfigContext();
    Server serverInstance = getServerByName(serverName);
    if (logger.isLoggable(Level.FINE))
        logFine("serverinstace " + serverInstance);
    JmsHost jmsHost = getResolvedJmsHost(serverInstance);
    return jmsHost;
}
Also used : JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

Example 19 with JmsHost

use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.

the class MQAddressList method getResolvedLocalJmsHostInServer.

/*static JmsHost jmsHostcopy = null;
     private JmsHost createJmsHostCopy(final JmsHost jmsHost, final Server server)
        {
        try {
            //jmsHost.deepCopy();
             ConfigSupport.apply(new SingleConfigCode<JmsService>() {
                public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {

                    final JmsHost jmsHost = param.createChild(JmsHost.class); //TODO: need a way to create a JmsHost instance
                    jmsHost.setAdminPassword(jmsHost.getAdminPassword());
                    jmsHost.setAdminUserName(jmsHost.getAdminUserName());
                    jmsHost.setName(jmsHost.getName());
                    jmsHost.setHost(jmsHost.getHost());
                    jmsHost.setPort(jmsHost.getPort());
                    MQAddressList.jmsHostcopy = jmsHost;
                    return jmsHost;
                }
            }, getConfigForServer(server).getJmsService());
        } catch(TransactionFailure tfe) {
            //tfe.printStackTrace();//todo: handle this exception
        }
        return jmsHostcopy;
     }*/
private JmsHost getResolvedLocalJmsHostInServer(final Server server) {
    Config config = getConfigForServer(server);
    if (config != null) {
        JmsService jmsService = config.getExtensionByType(JmsService.class);
        JmsHost jmsHost = null;
        if (JMSServiceType.LOCAL.toString().equals(jmsService.getType()) || JMSServiceType.EMBEDDED.toString().equals(jmsService.getType())) {
            jmsHost = getDefaultJmsHost(jmsService);
        }
        return (jmsHost);
    }
    return null;
}
Also used : JmsService(com.sun.enterprise.connectors.jms.config.JmsService) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

Example 20 with JmsHost

use of com.sun.enterprise.connectors.jms.config.JmsHost in project Payara by payara.

the class MQAddressList method getMasterJmsHostInCluster.

private JmsHost getMasterJmsHostInCluster(String clusterName) throws Exception {
    Domain domain = Globals.get(Domain.class);
    Cluster cluster = domain.getClusterNamed(clusterName);
    /*
           Since GF 3.1 - Added a new way to configure the master broker
           Check if a master broker has been configured by looking at jmsService.getMasterBroker
           If it is configured, return th
           If not, use the first configured server in the cluster list as the master broker
         */
    Config config = domain.getConfigNamed(cluster.getConfigRef());
    JmsService jmsService = config.getExtensionByType(JmsService.class);
    Server masterBrokerInstance = null;
    String masterBrokerInstanceName = jmsService.getMasterBroker();
    if (masterBrokerInstanceName != null) {
        masterBrokerInstance = domain.getServerNamed(masterBrokerInstanceName);
    } else {
        Server[] buddies = getServersInCluster(cluster);
        // there may be hosts attached to an NA that is down
        if (buddies.length > 0) {
            masterBrokerInstance = buddies[0];
        }
    }
    final JmsHost copy = getResolvedJmsHost(masterBrokerInstance);
    if (copy != null)
        return copy;
    else
        throw new RuntimeException("No JMS hosts available to select as Master");
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

Aggregations

JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)24 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)10 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)6 PropertyVetoException (java.beans.PropertyVetoException)6 ActionReport (org.glassfish.api.ActionReport)4 com.sun.enterprise.config.serverbeans (com.sun.enterprise.config.serverbeans)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ActiveJmsResourceAdapter (com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter)2 MQAddressList (com.sun.enterprise.connectors.jms.system.MQAddressList)2 DummyNetworkListener (com.sun.enterprise.v3.services.impl.DummyNetworkListener)2 GrizzlyService (com.sun.enterprise.v3.services.impl.GrizzlyService)2 Method (java.lang.reflect.Method)2 java.util (java.util)2 ResourceAdapter (javax.resource.spi.ResourceAdapter)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 Property (org.jvnet.hk2.config.types.Property)2 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1