use of com.sun.enterprise.v3.services.impl.DummyNetworkListener 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;
}
}
}
}
}
}
use of com.sun.enterprise.v3.services.impl.DummyNetworkListener 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;
}
use of com.sun.enterprise.v3.services.impl.DummyNetworkListener in project Payara by payara.
the class ORBConnectorStartup method initializeLazyListener.
/**
* Start Grizzly based ORB lazy listener, which is going to initialize
* ORB container on first request.
*/
private void initializeLazyListener() {
final IiopService iiopService = config.getExtensionByType(IiopService.class);
if (iiopService != null) {
List<IiopListener> iiopListenerList = iiopService.getIiopListener();
for (IiopListener oneListener : iiopListenerList) {
if (Boolean.valueOf(oneListener.getEnabled()) && Boolean.valueOf(oneListener.getLazyInit())) {
NetworkListener dummy = new DummyNetworkListener();
dummy.setPort(oneListener.getPort());
dummy.setAddress(oneListener.getAddress());
dummy.setProtocol("light-weight-listener");
dummy.setTransport("tcp");
dummy.setName("iiop-service");
grizzlyService.createNetworkProxy(dummy);
}
}
}
}
Aggregations