Search in sources :

Example 1 with GrizzlyService

use of com.sun.enterprise.v3.services.impl.GrizzlyService in project Payara by payara.

the class ActiveJmsResourceAdapter method destroy.

@Override
public void destroy() {
    try {
        JmsService jmsService = getJmsService();
        if (jmsService != null && jmsService.getType().equals("DISABLED")) {
            return;
        }
        if (connectorRuntime.isServer() && grizzlyListenerInit && jmsService != null && EMBEDDED.equalsIgnoreCase(jmsService.getType())) {
            GrizzlyService grizzlyService = null;
            try {
                grizzlyService = Globals.get(GrizzlyService.class);
            } catch (MultiException rle) {
            // if GrizzlyService was shut down already, skip removing the proxy.
            }
            if (grizzlyService != null) {
                synchronized (grizzlyListeners) {
                    if (grizzlyListeners.size() > 0) {
                        String[] listeners = grizzlyListeners.toArray(new String[grizzlyListeners.size()]);
                        for (String listenerName : listeners) {
                            try {
                                grizzlyService.removeNetworkProxy(listenerName);
                                grizzlyListeners.remove(listenerName);
                            } catch (Exception e) {
                                LogHelper.log(_logger, Level.WARNING, JMSLoggerInfo.SHUTDOWN_FAIL_GRIZZLY, e, listenerName);
                            }
                        }
                    }
                }
            }
            grizzlyListenerInit = false;
        }
    } catch (Throwable th) {
        if (_logger.isLoggable(Level.WARNING)) {
            _logger.log(Level.WARNING, JMSLoggerInfo.SHUTDOWN_FAIL_JMSRA, new Object[] { th.getMessage() });
        }
        throw new RuntimeException(th);
    }
    super.destroy();
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) GrizzlyService(com.sun.enterprise.v3.services.impl.GrizzlyService) MultiException(org.glassfish.hk2.api.MultiException) MultiException(org.glassfish.hk2.api.MultiException) PrivilegedActionException(java.security.PrivilegedActionException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 2 with GrizzlyService

use of com.sun.enterprise.v3.services.impl.GrizzlyService in project Payara by payara.

the class ActiveJmsResourceAdapter method initializeLazyListener.

/**
 * Start Grizzly based JMS lazy listener, which is going to initialize
 * JMS container on first request.
 * @param jmsService
 * @throws com.sun.enterprise.connectors.jms.system.JmsInitialisationException
 */
public void initializeLazyListener(JmsService jmsService) throws JmsInitialisationException {
    if (jmsService != null && jmsService.getType().equals("DISABLED")) {
        return;
    }
    if (jmsService != null) {
        if (EMBEDDED.equalsIgnoreCase(jmsService.getType()) && !grizzlyListenerInit) {
            GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
            if (grizzlyService != null) {
                List<JmsHost> jmsHosts = jmsService.getJmsHost();
                for (JmsHost oneHost : jmsHosts) {
                    if (Boolean.valueOf(oneHost.getLazyInit()) && !doBind) {
                        String jmsHost = null;
                        if (oneHost.getHost() != null && "localhost".equals(oneHost.getHost())) {
                            jmsHost = "0.0.0.0";
                        } else {
                            jmsHost = oneHost.getHost();
                        }
                        NetworkListener dummy = new DummyNetworkListener();
                        dummy.setPort(oneHost.getPort());
                        dummy.setAddress(jmsHost);
                        dummy.setType("proxy");
                        dummy.setProtocol(JMS_SERVICE);
                        dummy.setTransport("tcp");
                        String name = GRIZZLY_PROXY_PREFIX + oneHost.getName();
                        dummy.setName(name);
                        synchronized (grizzlyListeners) {
                            Future<Result<Thread>> createNetworkProxy = grizzlyService.createNetworkProxy(dummy);
                            try {
                                Result<Thread> result = createNetworkProxy.get();
                                if (result.exception() != null) {
                                    throw new JmsInitialisationException(MessageFormat.format("Cannot initialise JMS broker listener on {0}:{1}", oneHost.getHost(), oneHost.getPort()), result.exception());
                                }
                            } catch (InterruptedException | ExecutionException ex) {
                                Logger.getLogger(ActiveJmsResourceAdapter.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            grizzlyListeners.add(name);
                        }
                        grizzlyListenerInit = true;
                    }
                }
            }
        }
    }
}
Also used : DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) Result(com.sun.enterprise.util.Result) GrizzlyService(com.sun.enterprise.v3.services.impl.GrizzlyService) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) ExecutionException(java.util.concurrent.ExecutionException) DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 3 with GrizzlyService

use of com.sun.enterprise.v3.services.impl.GrizzlyService in project Payara by payara.

the class JMSConfigListener method changed.

/**
 * Implementation of org.jvnet.hk2.config.ConfigListener
 */
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    // Events that we can't process now because they require server restart.
    jmsService = serverConfig.getExtensionByType(JmsService.class);
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "In JMSConfigListener - received config event");
    }
    Domain domain = Globals.get(Domain.class);
    String jmsProviderPort = null;
    ServerContext serverContext = Globals.get(ServerContext.class);
    Server thisServer = domain.getServerNamed(serverContext.getInstanceName());
    // if(thisServer.isDas() || thisServer.getCluster() == null)
    {
    // _logger.log(Level.FINE,"JMSConfigListerner server is either das or a stand-alone instance - hence ignoring");
    // return null;
    }
    for (int i = 0; i < events.length; i++) {
        // for (PropertyChangeEvent event : events) {
        PropertyChangeEvent event = events[i];
        String eventName = event.getPropertyName();
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "In JMSConfigListener " + eventName + oldValue + newValue);
        }
        if (oldValue != null && oldValue.equals(newValue)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Event " + eventName + " did not change existing value of " + oldValue);
            }
            continue;
        }
        if (event.getSource().toString().indexOf("connectors.jms.config.JmsService") != -1) {
            boolean notifyFlag = true;
            if (oldValue != null && newValue == null && "jms-host".equals(event.getPropertyName())) {
                JmsHost jmsHost = (JmsHost) oldValue;
                String name = ActiveJmsResourceAdapter.GRIZZLY_PROXY_PREFIX + jmsHost.getName();
                ActiveJmsResourceAdapter adapter = Globals.get(ActiveJmsResourceAdapter.class);
                if (adapter.getGrizzlyListeners().contains(name)) {
                    GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
                    synchronized (adapter.getGrizzlyListeners()) {
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, "Stopping Grizzly proxy " + name);
                        }
                        grizzlyService.removeNetworkProxy(name);
                        adapter.getGrizzlyListeners().remove(name);
                    }
                    notifyFlag = false;
                }
            }
            if (notifyFlag) {
                UnprocessedChangeEvent uchangeEvent = new UnprocessedChangeEvent(event, "restart required");
                unprocessedEvents.add(uchangeEvent);
            }
        } else if (event.getSource().toString().indexOf("connectors.jms.config.JmsHost") != -1) {
            if (oldValue == null && newValue != null && "name".equals(event.getPropertyName())) {
                JmsProviderLifecycle lifecycle = Globals.get(JmsProviderLifecycle.class);
                JmsHost jmsHost = (JmsHost) event.getSource();
                if (ActiveJmsResourceAdapter.EMBEDDED.equalsIgnoreCase(jmsService.getType())) {
                    ActiveJmsResourceAdapter adapter = Globals.get(ActiveJmsResourceAdapter.class);
                    if (!adapter.getDoBind()) {
                        if (Boolean.valueOf(jmsHost.getLazyInit())) {
                            String host = null;
                            if (jmsHost.getHost() != null && "localhost".equals(jmsHost.getHost())) {
                                host = "0.0.0.0";
                            } else {
                                host = jmsHost.getHost();
                            }
                            try {
                                GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
                                NetworkListener dummy = new DummyNetworkListener();
                                dummy.setPort(jmsHost.getPort());
                                dummy.setAddress(host);
                                dummy.setType("proxy");
                                dummy.setProtocol(ActiveJmsResourceAdapter.JMS_SERVICE);
                                dummy.setTransport("tcp");
                                String name = ActiveJmsResourceAdapter.GRIZZLY_PROXY_PREFIX + jmsHost.getName();
                                dummy.setName(name);
                                synchronized (adapter.getGrizzlyListeners()) {
                                    if (_logger.isLoggable(Level.FINE)) {
                                        _logger.log(Level.FINE, "Starting Grizzly proxy " + name + " on port " + jmsHost.getPort());
                                    }
                                    grizzlyService.createNetworkProxy(dummy);
                                    adapter.getGrizzlyListeners().add(name);
                                }
                                return unprocessedEvents.size() > 0 ? new UnprocessedChangeEvents(unprocessedEvents) : null;
                            } catch (Exception e) {
                                LogHelper.log(_logger, Level.WARNING, JMSLoggerInfo.GRIZZLY_START_FAILURE, e);
                            }
                        }
                    }
                }
            }
        }
        if ("JMS_PROVIDER_PORT".equals(newValue)) {
            // The value is in the next event
            PropertyChangeEvent nextevent = events[i + 1];
            jmsProviderPort = (String) nextevent.getNewValue();
        }
        if (event.getSource() instanceof JmsService) {
            if (eventName.equals(ServerTags.MASTER_BROKER)) {
                String oldMB = oldValue != null ? oldValue.toString() : null;
                String newMB = newValue != null ? newValue.toString() : null;
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Got JmsService Master Broker change event " + event.getSource() + " " + eventName + " " + oldMB + " " + newMB);
                }
                if (newMB != null) {
                    Server newMBServer = domain.getServerNamed(newMB);
                    if (newMBServer != null) {
                        Node node = domain.getNodeNamed(newMBServer.getNodeRef());
                        String newMasterBrokerPort = JmsRaUtil.getJMSPropertyValue(newMBServer);
                        if (newMasterBrokerPort == null)
                            newMasterBrokerPort = getDefaultJmsHost(jmsService).getPort();
                        String newMasterBrokerHost = node.getNodeHost();
                        aresourceAdapter.setMasterBroker(newMasterBrokerHost + ":" + newMasterBrokerPort);
                    }
                }
            }
        }
        if (eventName.equals(ServerTags.SERVER_REF)) {
            // if(event instanceof ServerRef){
            String oldServerRef = oldValue != null ? oldValue.toString() : null;
            String newServerRef = newValue != null ? newValue.toString() : null;
            if (oldServerRef != null && newServerRef == null && !thisServer.isDas()) {
                // instance has been deleted
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Got Cluster change event for server_ref" + event.getSource() + " " + eventName + " " + oldServerRef + " " + null);
                }
                String url = getBrokerList();
                aresourceAdapter.setClusterBrokerList(url);
                break;
            }
        // 
        }
        // else skip
        if (event.getSource() instanceof Server) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "In JMSConfigListener - recieved cluster event " + event.getSource());
            }
            Server changedServer = (Server) event.getSource();
            if (thisServer.isDas())
                return null;
            if (jmsProviderPort != null) {
                String nodeName = changedServer.getNodeRef();
                String nodeHost = null;
                if (nodeName != null)
                    nodeHost = domain.getNodeNamed(nodeName).getNodeHost();
                String url = getBrokerList();
                url = url + ",mq://" + nodeHost + ":" + jmsProviderPort;
                aresourceAdapter.setClusterBrokerList(url);
                break;
            }
        }
    }
    return unprocessedEvents.size() > 0 ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ServerContext(org.glassfish.internal.api.ServerContext) GrizzlyService(com.sun.enterprise.v3.services.impl.GrizzlyService) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

GrizzlyService (com.sun.enterprise.v3.services.impl.GrizzlyService)3 JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)2 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)2 DummyNetworkListener (com.sun.enterprise.v3.services.impl.DummyNetworkListener)2 ExecutionException (java.util.concurrent.ExecutionException)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 Result (com.sun.enterprise.util.Result)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 URISyntaxException (java.net.URISyntaxException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)1 MultiException (org.glassfish.hk2.api.MultiException)1 ServerContext (org.glassfish.internal.api.ServerContext)1 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)1 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)1