Search in sources :

Example 16 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener 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 17 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener 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)

Example 18 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class PayaraInstanceImpl method initialiseInstanceDescriptor.

private void initialiseInstanceDescriptor() {
    boolean liteMember = false;
    int hazelcastPort = 5900;
    InetAddress hostname = null;
    // Get the Hazelcast specific information
    if (hazelcast.isEnabled()) {
        instanceName = hazelcast.getMemberName();
        instanceGroup = hazelcast.getMemberGroup();
        myCurrentID = hazelcast.getUUID();
        liteMember = hazelcast.isLite();
        hazelcastPort = hazelcast.getPort();
        hostname = hazelcast.getInstance().getCluster().getLocalMember().getSocketAddress().getAddress();
    } else {
        instanceName = "payara-micro";
        instanceGroup = "no-cluster";
    }
    // Get this instance's runtime type
    String instanceType = environment.getRuntimeType().toString();
    // Get the ports in use by this instance from its network listener configs
    List<Integer> ports = new ArrayList<>();
    List<Integer> sslPorts = new ArrayList<>();
    int adminPort = 0;
    for (NetworkListener networkListener : context.getConfigBean().getConfig().getNetworkConfig().getNetworkListeners().getNetworkListener()) {
        // Skip the network listener if it isn't enabled
        if (Boolean.parseBoolean(networkListener.getEnabled())) {
            // Check if this listener is using HTTP or HTTPS
            if (networkListener.findProtocol().getSecurityEnabled().equals("false")) {
                // Check if this listener is the admin listener
                if (networkListener.getName().equals(context.getConfigBean().getConfig().getAdminListener().getName())) {
                    // Micro instances can use the admin listener as both an admin and HTTP port
                    if (instanceType.equals("MICRO")) {
                        ports.add(Integer.parseInt(networkListener.getPort()));
                    }
                    adminPort = Integer.parseInt(networkListener.getPort());
                } else {
                    // If this listener isn't the admin listener, it must be an HTTP listener
                    ports.add(Integer.parseInt(networkListener.getPort()));
                }
            } else if (networkListener.findProtocol().getSecurityEnabled().equals("true")) {
                if (networkListener.getName().equals(context.getConfigBean().getConfig().getAdminListener().getName())) {
                    // Micro instances can use the admin listener as both an admin and HTTPS port
                    if (instanceType.equals("MICRO")) {
                        ports.add(Integer.parseInt(networkListener.getPort()));
                    }
                    adminPort = Integer.parseInt(networkListener.getPort());
                } else {
                    // If this listener isn't the admin listener, it must be an HTTPS listener
                    sslPorts.add(Integer.parseInt(networkListener.getPort()));
                }
            }
        }
    }
    // Initialise the instance descriptor and set all of its attributes
    try {
        // If Hazelcast is being rebooted dynamically, we don't want to lose the already registered applications
        Collection<ApplicationDescriptor> deployedApplications = new ArrayList<>();
        if (me != null) {
            deployedApplications = me.getDeployedApplications();
        }
        me = new InstanceDescriptorImpl(myCurrentID);
        me.setInstanceName(instanceName);
        me.setInstanceGroup(instanceGroup);
        for (int port : ports) {
            me.addHttpPort(port);
        }
        for (int sslPort : sslPorts) {
            me.addHttpsPort(sslPort);
        }
        me.setAdminPort(adminPort);
        me.setHazelcastPort(hazelcastPort);
        me.setLiteMember(liteMember);
        me.setInstanceType(instanceType);
        if (hostname != null) {
            me.setHostName(hostname);
        }
        // one
        if (!deployedApplications.isEmpty()) {
            for (ApplicationDescriptor application : deployedApplications) {
                me.addApplication(application);
            }
        }
        // Register the instance descriptor to the cluster if it's enabled
        if (cluster.isEnabled()) {
            cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, me);
        }
    } catch (UnknownHostException ex) {
        logger.log(Level.SEVERE, "Could not find local hostname", ex);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) ApplicationDescriptor(fish.payara.micro.data.ApplicationDescriptor) InstanceDescriptorImpl(fish.payara.appserver.micro.services.data.InstanceDescriptorImpl) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 19 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class IIOPUtils method postConstruct.

// private GlassFishORBManager gfORBMgr;
public void postConstruct() {
    processType = processEnv.getProcessType();
    if (processEnv.getProcessType().isServer()) {
        Config c = services.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
        iiopService = c.getExtensionByType(IiopService.class);
        final Collection<ThreadPool> threadPool = c.getThreadPools().getThreadPool();
        final Collection<NetworkListener> listeners = allByContract(NetworkListener.class);
        final Set<String> names = new TreeSet<String>();
        threadPools = new ArrayList<ThreadPool>();
        for (NetworkListener listener : listeners) {
            names.add(listener.getThreadPool());
        }
        for (ThreadPool pool : threadPool) {
            if (!names.contains(pool.getName())) {
                threadPools.add(pool);
            }
        }
        serverRefs = allByContract(ServerRef.class);
    }
    IIOPUtils.initMe(this);
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) IiopService(org.glassfish.orb.admin.config.IiopService) TreeSet(java.util.TreeSet) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 20 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class RestMonitoringEndpointDecider method setValues.

private void setValues() {
    NetworkListener networkListener = config.getAdminListener();
    ThreadPool threadPool = networkListener.findThreadPool();
    // Set Thread pool size
    if (threadPool != null) {
        try {
            maxThreadPoolSize = Integer.parseInt(threadPool.getMaxThreadPoolSize());
        } catch (NumberFormatException ex) {
        }
    }
    String defaultVirtualServer = networkListener.findHttpProtocol().getHttp().getDefaultVirtualServer();
    hosts = Collections.unmodifiableList(Arrays.asList(defaultVirtualServer));
    // Set network address
    try {
        address = InetAddress.getByName(networkListener.getAddress());
    } catch (UnknownHostException e) {
        throw new IllegalStateException(e);
    }
    // Set the context root and port number
    if (ServerTags.ADMIN_LISTENER_ID.equals(networkListener.getName())) {
        // Get the context root from the rest monitoring service
        if (restMonitoringServiceConfiguration == null) {
            contextRoot = DEFAULT_CONTEXT_ROOT;
        } else {
            contextRoot = restMonitoringServiceConfiguration.getContextRoot();
        }
        try {
            port = Integer.parseInt(networkListener.getPort());
        } catch (NumberFormatException ne) {
            port = DEFAULT_ADMIN_PORT;
        }
    } else {
        try {
            port = Integer.parseInt(networkListener.getPort());
        } catch (NumberFormatException ne) {
            port = DEFAULT_ADMIN_PORT;
        }
        // Get the context root from the rest monitoring service
        if (restMonitoringServiceConfiguration == null) {
            contextRoot = DEFAULT_CONTEXT_ROOT;
        } else {
            contextRoot = restMonitoringServiceConfiguration.getContextRoot();
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)74 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)21 Protocol (org.glassfish.grizzly.config.dom.Protocol)18 Config (com.sun.enterprise.config.serverbeans.Config)17 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)14 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)12 Test (org.junit.Test)11 ActionReport (org.glassfish.api.ActionReport)10 CommandTarget (org.glassfish.config.support.CommandTarget)9 Target (org.glassfish.internal.api.Target)9 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 HttpService (com.sun.enterprise.config.serverbeans.HttpService)7 ArrayList (java.util.ArrayList)7 Protocols (org.glassfish.grizzly.config.dom.Protocols)7 ObservableBean (org.jvnet.hk2.config.ObservableBean)7 Transactions (org.jvnet.hk2.config.Transactions)7 IOException (java.io.IOException)6 Http (org.glassfish.grizzly.config.dom.Http)6 PropertyVetoException (java.beans.PropertyVetoException)5 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)5