All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.netbeans.modules.glassfish.common.StopProfilingTask Maven / Gradle / Ivy

There is a newer version: RELEASE240
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.netbeans.modules.glassfish.common;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.modules.glassfish.tooling.TaskEvent;
import org.netbeans.modules.glassfish.tooling.TaskState;
import org.netbeans.modules.glassfish.tooling.TaskStateListener;
import org.netbeans.modules.glassfish.spi.GlassfishModule;
import org.openide.util.NbBundle;

/**
 * Task for stopping server that was started in profile mode.
 * 
 * @author Peter Benedikovic
 */
public class StopProfilingTask extends BasicTask {

    private final CommonServerSupport support;

    /**
     * 
     * @param support common support object for the server instance being stopped
     * @param stateListener state monitor to track start progress
     */
    public StopProfilingTask(final CommonServerSupport support, TaskStateListener stateListener) {
        super(support.getInstance(), stateListener, new TaskStateListener() {

            @Override
           public void operationStateChanged(TaskState newState,
           TaskEvent event, String... args) {
                if(newState == TaskState.COMPLETED) {
                    support.setServerState(GlassfishModule.ServerState.STOPPED);
                } else if(newState == TaskState.FAILED) {
                    support.setServerState(GlassfishModule.ServerState.STOPPED_JVM_PROFILER);
                }
            }
        });
        this.support = support;
    }
    
    @Override
    public TaskState call() {
        Logger.getLogger("glassfish").log(Level.FINEST, "StopLocalTask.call() called on thread {0}", Thread.currentThread().getName()); // NOI18N
        
        if (support.getLocalStartProcess() != null) {
            LogViewMgr logger = LogViewMgr.getInstance(instance.getProperty(GlassfishModule.URL_ATTR));
            String msg = NbBundle.getMessage(BasicTask.class, "MSG_SERVER_PROFILING_STOPPED", instanceName);
            logger.write(msg, false);
            logger.stopReaders();
            support.stopLocalStartProcess();
            return fireOperationStateChanged(TaskState.COMPLETED,
                    TaskEvent.CMD_COMPLETED,
                    "MSG_SERVER_PROFILING_STOPPED", instanceName);
        } else {
            return fireOperationStateChanged(TaskState.FAILED,
                    TaskEvent.CMD_FAILED,
                    "MSG_STOP_SERVER_FAILED", instanceName);
        }
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy