Skip to content

Commit

Permalink
Merged in PAYARA-372-jms-broker-issues-when-broker (pull request paya…
Browse files Browse the repository at this point in the history
…ra#9)

PAYARA-372 change JMS broker initialisation so that the broker won't boot if it receives a BindException because its specified port is in use.
  • Loading branch information
smillidge committed Aug 19, 2015
2 parents 3a982fc + 8b33150 commit 74cd1e6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
only if the new code is made subject to such option by the copyright
holder.

Portions Copyright [2015] [C2B2 Consulting Limited]
-->

<!initPage
Expand Down Expand Up @@ -128,7 +129,7 @@
foreach (var="server" list="#{pageSession.serverList}") {
gf.restRequest(endpoint="#{sessionScope.REST_URL}/servers/server/#{server}", method="GET", result="#{requestScope.serverDetails}");
if ("#{pageSession.configName} = #{requestScope.serverDetails.data.extraProperties.entity.configRef}") {
gf.restRequest(endpoint="#{sessionScope.REST_URL}/servers/server/#{server}/jms-ping", method="get", result="#{requestScope.pingResults}");
gf.restRequest(endpoint="#{sessionScope.REST_URL}/servers/server/#{server}/jms-ping?target=#{server}", method="get", result="#{requestScope.pingResults}");
if ("(#{requestScope.pingResults.responseCode} = 200)") {
prepareAlertMsg(type="success", summary="$resource{i18nc.msg.PingSucceed}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2015] [C2B2 Consulting Limited]

package com.sun.enterprise.connectors.jms.system;

import java.io.File;
import java.lang.reflect.Method;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SocketChannel;
Expand Down Expand Up @@ -75,7 +75,6 @@
import com.sun.enterprise.config.serverbeans.Applications;
import com.sun.enterprise.config.serverbeans.AvailabilityService;
import com.sun.enterprise.config.serverbeans.Clusters;
import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.JavaConfig;
import com.sun.enterprise.config.serverbeans.JmxConnector;
Expand All @@ -102,10 +101,14 @@
import com.sun.enterprise.deployment.MessageDestinationDescriptor;
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.deployment.runtime.BeanPoolDescriptor;
import com.sun.enterprise.util.Result;
import com.sun.enterprise.util.SystemPropertyConstants;
import com.sun.enterprise.util.i18n.StringManager;
import com.sun.enterprise.v3.services.impl.DummyNetworkListener;
import com.sun.enterprise.v3.services.impl.GrizzlyService;
import java.text.MessageFormat;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.glassfish.admin.mbeanserver.JMXStartupService;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.api.naming.GlassfishNamingManager;
Expand Down Expand Up @@ -446,7 +449,7 @@ public Set<String> getGrizzlyListeners() {
* Start Grizzly based JMS lazy listener, which is going to initialize
* JMS container on first request.
*/
public void initializeLazyListener(JmsService jmsService) {
public void initializeLazyListener(JmsService jmsService) throws JmsInitialisationException {
if (jmsService != null) {
if (EMBEDDED.equalsIgnoreCase(jmsService.getType()) && !grizzlyListenerInit) {
GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
Expand All @@ -469,7 +472,15 @@ public void initializeLazyListener(JmsService jmsService) {
String name = GRIZZLY_PROXY_PREFIX + oneHost.getName();
dummy.setName(name);
synchronized (grizzlyListeners) {
grizzlyService.createNetworkProxy(dummy);
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;
Expand All @@ -488,7 +499,12 @@ protected void startResourceAdapter(BootstrapContext bootstrapContext) throws Re
ServerContext serverContext = Globals.get(ServerContext.class);
Server server = domain.getServerNamed(serverContext.getInstanceName());
JmsService jmsService = server.getConfig().getExtensionByType(JmsService.class);
initializeLazyListener(jmsService);
try {
initializeLazyListener(jmsService);
} catch (Throwable ex) {
Logger.getLogger(ActiveJmsResourceAdapter.class.getName()).log(Level.SEVERE, null, ex);
throw new ResourceAdapterInternalException(ex);
}
}
//System.setProperty("imq.jmsra.direct.clustered", "true");
AccessController.doPrivileged
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright (c) 2015 C2B2 Consulting Limited. All rights reserved.
The contents of this file are subject to the terms of the Common Development
and Distribution License("CDDL") (collectively, the "License"). You
may not use this file except in compliance with the License. You can
obtain a copy of the License at
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
or packager/legal/LICENSE.txt. See the License for the specific
language governing permissions and limitations under the License.
When distributing the software, include this License Header Notice in each
file and include the License file at packager/legal/LICENSE.txt.
*/
package com.sun.enterprise.connectors.jms.system;

/**
* Exception class thrown when there is a problem initialising the broker
* @author steve
*/
public class JmsInitialisationException extends Exception {
private static final long serialVersionUID = -2763569052869563797L;

public JmsInitialisationException() {
}

public JmsInitialisationException(String message) {
super(message);
}

public JmsInitialisationException(Throwable cause) {
super(cause);
}

public JmsInitialisationException(String message, Throwable cause) {
super(message, cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/

// Portions Copyright [2015] [C2B2 Consulting Limited]
package com.sun.enterprise.connectors.jms.system;

//import org.glassfish.api.monitoring.MonitoringItem;
Expand All @@ -61,13 +61,14 @@
import com.sun.enterprise.config.serverbeans.Config;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import org.glassfish.api.admin.ServerEnvironment;
//import com.sun.enterprise.config.serverbeans.MonitoringService;

//import java.beans.PropertyVetoException;
//import java.util.logging.Level;
Expand Down Expand Up @@ -96,8 +97,9 @@ public class JmsProviderLifecycle implements PostConstruct{

@Inject
private ActiveJmsResourceAdapter activeJmsResourceAdapter;


public void postConstruct()
public void postConstruct()
{
final JmsService jmsService = config.getExtensionByType(JmsService.class);
if (eagerStartupRequired())
Expand All @@ -110,7 +112,12 @@ public void postConstruct()
e.printStackTrace();
}
}
activeJmsResourceAdapter.initializeLazyListener(jmsService);
try {
activeJmsResourceAdapter.initializeLazyListener(jmsService);
} catch (JmsInitialisationException ex) {
Logger.getLogger(JmsProviderLifecycle.class.getName()).log(Level.SEVERE, null, ex);
throw new IllegalStateException(ex);
}
configureConfigListener();
//createMonitoringConfig();

Expand Down

0 comments on commit 74cd1e6

Please sign in to comment.