Skip to content

Commit

Permalink
PAYARA-1561 Payara Micro fails fast if there is an error in boot (#1690)
Browse files Browse the repository at this point in the history
* Payara-micro now fails fast

* Added copyright
  • Loading branch information
Cousjava authored and smillidge committed Jun 20, 2017
1 parent 39503f8 commit 1d7999e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,12 @@ public ClassLoader setThreadBootstrapLoader() {
return result;
}

public static void main(String ... args) throws Exception {
PayaraMicroLauncher.main(args);
public static void main(String ... args) {
try {
PayaraMicroLauncher.main(args);
} catch (Exception ex) {
Logger.getLogger(PayaraMicro.class.getName()).log(Level.SEVERE, null, ex);
}
}

private PayaraMicro() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void stop() throws GlassFishException {

status = Status.STOPPING;
kernel.stop();
habitat.shutdown();
status = Status.STOPPED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,12 @@ public PayaraMicroRuntime bootStrap() throws BootstrapException {
long end = System.currentTimeMillis();
dumpFinalStatus(end - start);
return runtime;
} catch (GlassFishException ex) {
} catch (Exception ex) {
try {
gf.dispose();
} catch (GlassFishException ex1) {
Logger.getLogger(PayaraMicroImpl.class.getName()).log(Level.SEVERE, null, ex1);
}
throw new BootstrapException(ex.getMessage(), ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/

package com.sun.enterprise.v3.server;
Expand Down Expand Up @@ -73,6 +75,7 @@
import org.glassfish.api.event.EventTypes;
import org.glassfish.api.event.Events;
import org.glassfish.common.util.Constants;
import org.glassfish.embeddable.GlassFishException;
import org.glassfish.hk2.api.ActiveDescriptor;
import org.glassfish.hk2.api.Descriptor;
import org.glassfish.hk2.api.DynamicConfiguration;
Expand Down Expand Up @@ -210,23 +213,32 @@ else if (POLICY_USE_NO_THREADS.equals(threadPolicy)) {

}

@Override
public synchronized void start() {
ClassLoader origCL = Thread.currentThread().getContextClassLoader();
try {
// See issue #5596 to know why we set context CL as common CL.
Thread.currentThread().setContextClassLoader(
commonCLS.getCommonClassLoader());
doStart();
} catch (GlassFishException ex) {
throw new RuntimeException (ex);
} finally {
// reset the context classloader. See issue GLASSFISH-15775
Thread.currentThread().setContextClassLoader(origCL);
}
}

private void doStart() {
private void doStart() throws GlassFishException {

run();
if (!run()){
//startup failed
logger.log(Level.SEVERE, "Failed to start, exiting");
throw new GlassFishException("Server failed to start");
}

//if (appInstanceListener.)

final CountDownLatch latch = new CountDownLatch(1);

// spwan a non-daemon thread that waits indefinitely for shutdown request.
Expand Down Expand Up @@ -272,11 +284,16 @@ public void run() {
}
}

public void run() {
/**
*
* @return True is startup succeeded, false if an error occurred preventing
* the server from starting
*/
public boolean run() {

if (context==null) {
System.err.println("Startup context not provided, cannot continue");
return;
return false;
}

if (platform==null) {
Expand Down Expand Up @@ -314,7 +331,7 @@ public void run() {

if (!proceedTo(InitRunLevel.VAL)) {
appInstanceListener.stopRecordingTimes();
return;
return false;
}

if (!logger.isLoggable(level)) {
Expand All @@ -330,12 +347,12 @@ public void run() {
appInstanceListener.startRecordingFutures();
if (!proceedTo(StartupRunLevel.VAL)) {
appInstanceListener.stopRecordingTimes();
return;
return false;
}

if (!postStartupJob()) {
appInstanceListener.stopRecordingTimes();
return;
return false;
}

if (logger.isLoggable(level)) {
Expand All @@ -347,7 +364,7 @@ public void run() {

if (!proceedTo(PostStartupRunLevel.VAL)) {
appInstanceListener.stopRecordingTimes();
return;
return false;
}

if (logger.isLoggable(level)) {
Expand All @@ -356,8 +373,13 @@ public void run() {
logger.log(level, "PostStartup level done in " +
(postStartupFinishTime - startupFinishTime) + " ms");
}
return true;
}

/**
*
* @return True if started successfully, false otherwise
*/
private boolean postStartupJob() {
LinkedList<Future<Result<Thread>>> futures = appInstanceListener.getFutures();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
/*
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright (c) 2016 Payara Foundation. 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.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2016-2017 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or 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://github.com/payara/Payara/blob/master/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 glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.nucleus.notification;

import com.google.common.eventbus.EventBus;
import fish.payara.nucleus.notification.domain.NotificationEvent;
import fish.payara.nucleus.notification.service.BaseNotifierService;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.api.StartupRunLevel;
import org.glassfish.hk2.runlevel.RunLevel;
import org.jvnet.hk2.annotations.Service;
Expand All @@ -37,7 +65,11 @@ public void register(BaseNotifierService notifier) {
}

public void unregister(BaseNotifierService notifier) {
eventBus.unregister(notifier);
try {
eventBus.unregister(notifier);
} catch (IllegalArgumentException e){
Logger.getLogger(NotificationEventBus.class.getCanonicalName()).log(Level.WARNING, "Tried to unregister" + notifier.toString() + ", it may not have been previously registered");
}
}

void postEvent(NotificationEvent event) {
Expand Down

0 comments on commit 1d7999e

Please sign in to comment.