This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 182772
Collapse All | Expand All

(-)a/j2ee.ant/antsrc/org/netbeans/modules/j2ee/ant/StartProfiledServer.java (-16 / +29 lines)
Lines 49-55 Link Here
49
import org.netbeans.api.java.platform.JavaPlatform;
49
import org.netbeans.api.java.platform.JavaPlatform;
50
import org.netbeans.api.java.platform.JavaPlatformManager;
50
import org.netbeans.api.java.platform.JavaPlatformManager;
51
import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
51
import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
52
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
52
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerProvider;
53
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerSession;
53
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
54
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
54
import org.openide.filesystems.*;
55
import org.openide.filesystems.*;
55
import org.netbeans.api.project.FileOwnerQuery;
56
import org.netbeans.api.project.FileOwnerQuery;
Lines 62-67 Link Here
62
 * Ant task that starts the server in profile mode.
63
 * Ant task that starts the server in profile mode.
63
 *
64
 *
64
 * @author sherold
65
 * @author sherold
66
 * @author ads
65
 */
67
 */
66
public class StartProfiledServer extends Task implements Deployment.Logger {
68
public class StartProfiledServer extends Task implements Deployment.Logger {
67
    
69
    
Lines 74-117 Link Here
74
    private String          javaPlatform;
76
    private String          javaPlatform;
75
    private CommandlineJava jvmarg       = new CommandlineJava();
77
    private CommandlineJava jvmarg       = new CommandlineJava();
76
    private Environment     env          = new Environment();
78
    private Environment     env          = new Environment();
79
    private String          profilerId;
80
    
77
    
81
    
78
    public void execute() throws BuildException {
82
    public void execute() throws BuildException {
79
      
83
        ProfilerProvider provider = ServerRegistry.getProfilerProvider( profilerId );
80
        Profiler profiler = ServerRegistry.getProfiler();
84
        if (provider == null) {
81
        if (profiler == null) {
85
            String msg = NbBundle.getMessage(StartProfiledServer.class, 
82
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_ProfierNotFound");
86
                    "MSG_ProfierNotFound");                     // NOI18N
83
            throw new BuildException(msg);
87
            throw new BuildException(msg);
84
        }
88
        }
85
        JavaPlatform[] installedPlatforms = JavaPlatformManager.getDefault().getInstalledPlatforms();
89
        JavaPlatform[] installedPlatforms = JavaPlatformManager.getDefault().
90
            getInstalledPlatforms();
86
        JavaPlatform platform = null;
91
        JavaPlatform platform = null;
87
        for (int i = 0; i < installedPlatforms.length; i++) {
92
        for (int i = 0; i < installedPlatforms.length; i++) {
88
            String platformName = (String)installedPlatforms[i].getProperties().get(PLAT_PROP_ANT_NAME);
93
            String platformName = (String)installedPlatforms[i].
94
                getProperties().get(PLAT_PROP_ANT_NAME);
89
            if (platformName != null && platformName.equals(javaPlatform)) {
95
            if (platformName != null && platformName.equals(javaPlatform)) {
90
                platform = installedPlatforms[i];
96
                platform = installedPlatforms[i];
91
            }
97
            }
92
        }
98
        }
93
        if (platform == null) {
99
        if (platform == null) {
94
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_PlatformNotFound", javaPlatform);
100
            String msg = NbBundle.getMessage(StartProfiledServer.class, 
101
                    "MSG_PlatformNotFound", javaPlatform);      // NOI18N
95
            throw new BuildException(msg);
102
            throw new BuildException(msg);
96
        }
103
        }
97
        String[] envvar = env.getVariables();
104
        String[] envvar = env.getVariables();
98
        if (envvar == null) {
105
        if (envvar == null) {
99
            envvar = new String[0];
106
            envvar = new String[0];
100
        }
107
        }
101
        ProfilerServerSettings settings = new ProfilerServerSettings(
108
        ProfilerServerSettings settings = new ProfilerServerSettings( platform,
102
                                                    platform,
109
                jvmarg.getVmCommand().getArguments(), envvar, 
103
                                                    jvmarg.getVmCommand().getArguments(), 
110
                getProject().getProperties());
104
                                                    envvar);
105
        FileObject fo = FileUtil.toFileObject(getProject().getBaseDir());
111
        FileObject fo = FileUtil.toFileObject(getProject().getBaseDir());
106
        fo.refresh(); // without this the "build" directory is not found in filesystems
112
        fo.refresh(); // without this the "build" directory is not found in filesystems
107
        J2eeModuleProvider jmp = (J2eeModuleProvider)FileOwnerQuery.getOwner(fo).getLookup().lookup(J2eeModuleProvider.class);
113
        J2eeModuleProvider jmp = (J2eeModuleProvider)FileOwnerQuery.getOwner(fo).
108
        ServerInstance si = ServerRegistry.getInstance().getServerInstance(jmp.getServerInstanceID());
114
            getLookup().lookup(J2eeModuleProvider.class);
109
        if (!si.startProfile(settings, forceRestart, this)) {
115
        ServerInstance si = ServerRegistry.getInstance().
116
            getServerInstance(jmp.getServerInstanceID());
117
        ProfilerSession session = provider.getSession(settings);
118
        if (!si.startProfile(session, forceRestart, this)) {
110
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_StartupFailed");
119
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_StartupFailed");
111
            throw new BuildException(msg);
120
            throw new BuildException(msg);
112
        }
121
        }
113
        log(NbBundle.getMessage(StartProfiledServer.class, "MSG_AttachingProfiler"));
122
        log(NbBundle.getMessage(StartProfiledServer.class, "MSG_AttachingProfiler"));
114
        if (!profiler.attachProfiler(getProject().getProperties())) {
123
        if (!session.attachProfiler()) {
115
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_AttachFailed");
124
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_AttachFailed");
116
            throw new BuildException(msg);
125
            throw new BuildException(msg);
117
        }
126
        }
Lines 143-148 Link Here
143
      startupTimeout = timeout;
152
      startupTimeout = timeout;
144
    }
153
    }
145
    
154
    
155
    public void setProfilerId( String id ){
156
        profilerId = id;
157
    }
158
    
146
    public void setJavaPlatform(String javaPlatform) {
159
    public void setJavaPlatform(String javaPlatform) {
147
        this.javaPlatform = javaPlatform;
160
        this.javaPlatform = javaPlatform;
148
    }
161
    }
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java (-119 / +267 lines)
Lines 64-69 Link Here
64
import org.netbeans.modules.j2ee.deployment.plugins.spi.JDBCDriverDeployer;
64
import org.netbeans.modules.j2ee.deployment.plugins.spi.JDBCDriverDeployer;
65
import org.openide.filesystems.*;
65
import org.openide.filesystems.*;
66
import java.util.*;
66
import java.util.*;
67
import java.util.concurrent.atomic.AtomicReference;
67
import java.util.logging.Level;
68
import java.util.logging.Level;
68
import java.util.logging.Logger;
69
import java.util.logging.Logger;
69
import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
70
import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
Lines 86-93 Link Here
86
import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment;
87
import org.netbeans.modules.j2ee.deployment.plugins.spi.MessageDestinationDeployment;
87
import org.netbeans.modules.j2ee.deployment.plugins.spi.ServerInstanceDescriptor;
88
import org.netbeans.modules.j2ee.deployment.plugins.spi.ServerInstanceDescriptor;
88
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
89
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
89
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport;
90
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerStateEvent;
90
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
91
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerStateListener;
92
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerProvider;
93
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerSession;
91
import org.openide.nodes.Node;
94
import org.openide.nodes.Node;
92
import org.openide.util.NbBundle;
95
import org.openide.util.NbBundle;
93
import org.openide.NotifyDescriptor;
96
import org.openide.NotifyDescriptor;
Lines 99-105 Link Here
99
import org.openide.windows.InputOutput;
102
import org.openide.windows.InputOutput;
100
103
101
104
102
public class ServerInstance implements Node.Cookie, Comparable {
105
106
public class ServerInstance implements Node.Cookie, Comparable, ProfilerStateListener {
103
    
107
    
104
    /** Server state is being checked or state changes is in progress */
108
    /** Server state is being checked or state changes is in progress */
105
    public static final int STATE_WAITING   = 1;
109
    public static final int STATE_WAITING   = 1;
Lines 161-168 Link Here
161
    
165
    
162
    private final ChangeSupport managerChangeSupport = new ChangeSupport(this);
166
    private final ChangeSupport managerChangeSupport = new ChangeSupport(this);
163
    
167
    
164
    private volatile static ServerInstance profiledServerInstance;
168
    private AtomicReference<ProfilerSession> mySession;
165
    private ProfilerServerSettings  profilerSettings;
169
    private ThreadLocal<ProgressUI> myProfilerStopUI;
170
    private Object myLock;
166
    
171
    
167
    private final DebuggerStateListener debuggerStateListener;
172
    private final DebuggerStateListener debuggerStateListener;
168
    
173
    
Lines 175-180 Link Here
175
        // listen to debugger changes so that we can update server status accordingly
180
        // listen to debugger changes so that we can update server status accordingly
176
        debuggerStateListener = new DebuggerStateListener();
181
        debuggerStateListener = new DebuggerStateListener();
177
        DebuggerManager.getDebuggerManager().addDebuggerListener(debuggerStateListener);
182
        DebuggerManager.getDebuggerManager().addDebuggerListener(debuggerStateListener);
183
        mySession = new AtomicReference<ProfilerSession>();
184
        myProfilerStopUI = new ThreadLocal<ProgressUI>();
185
        myLock = new Object();
178
    }
186
    }
179
    
187
    
180
    /** Return this server instance InstanceProperties. */
188
    /** Return this server instance InstanceProperties. */
Lines 349-373 Link Here
349
    public void refresh() {
357
    public void refresh() {
350
        RequestProcessor.getDefault().post(new Runnable() {
358
        RequestProcessor.getDefault().post(new Runnable() {
351
            public void run() {
359
            public void run() {
360
                synchronized( myLock ){
352
                try {
361
                try {
353
                    int oldState = getServerState();
362
                    int oldState = getServerState();
354
                    setServerState(STATE_WAITING);
363
                    setServerState(STATE_WAITING);
355
                    if (ServerInstance.this == profiledServerInstance) {
364
                    ProfilerSession session = getProfilerSession();
356
                        int profState = ProfilerSupport.getState();
365
                    if (session != null) {
357
                        if (profState == ProfilerSupport.STATE_STARTING) {
366
                        int profState = session.getState();
367
                        if (profState == ProfilerSession.STATE_STARTING) {
358
                            setServerState(ServerInstance.STATE_PROFILER_STARTING);
368
                            setServerState(ServerInstance.STATE_PROFILER_STARTING);
359
                            return;
369
                            return;
360
                        } else if (profState == ProfilerSupport.STATE_BLOCKING) {
370
                        } else if (profState == ProfilerSession.STATE_BLOCKING) {
361
                            setServerState(ServerInstance.STATE_PROFILER_BLOCKING);
371
                            setServerState(ServerInstance.STATE_PROFILER_BLOCKING);
362
                            return;
372
                            return;
363
                        } else if (profState == ProfilerSupport.STATE_PROFILING
373
                        } else if (profState == ProfilerSession.STATE_PROFILING
364
                                   || profState == ProfilerSupport.STATE_RUNNING) {
374
                                   || profState == ProfilerSession.STATE_RUNNING) {
365
                            initCoTarget();
375
                            initCoTarget();
366
                            setServerState(ServerInstance.STATE_PROFILING);
376
                            setServerState(ServerInstance.STATE_PROFILING);
367
                            return;
377
                            return;
368
                        } else {
378
                        } else if ( profState == ProfilerSession.STATE_STOPPING ){
379
                            reset();
380
                            setServerState(ServerInstance.STATE_STOPPED);
369
                            //  profiler is inactive - has been shutdown
381
                            //  profiler is inactive - has been shutdown
370
                            profiledServerInstance = null;
382
                            mySession.set( null );
383
                            return;
384
                        }
385
                        else if   (profState == ProfilerSession.STATE_INACTIVE)
386
                        {
387
                            //  profiler is inactive - has been shutdown
388
                            mySession.set( null );
371
                        }
389
                        }
372
                    }
390
                    }
373
                    if (isSuspended()) {
391
                    if (isSuspended()) {
Lines 395-400 Link Here
395
                    }
413
                    }
396
                }
414
                }
397
            }
415
            }
416
            }
398
        });
417
        });
399
    }
418
    }
400
    
419
    
Lines 523-535 Link Here
523
            // TODO revert the Glassfish /w profiler related workaround 
542
            // TODO revert the Glassfish /w profiler related workaround 
524
            // once profiling uses the same startup sequence as debugging eg.
543
            // once profiling uses the same startup sequence as debugging eg.
525
            try {
544
            try {
545
                ProfilerSession session = getProfilerSession();
526
                if (! isRunning() && startServer != null && startServer.needsStartForTargetList()) {
546
                if (! isRunning() && startServer != null && startServer.needsStartForTargetList()) {
527
                    // GF workaround
547
                    // GF workaround
528
                    // the guard condition introduced
548
                    // the guard condition introduced
529
                    // *** original line
549
                    // *** original line
530
                    // start();
550
                    // start();
531
                    // ***
551
                    // ***
532
                    if (ProfilerSupport.getState() == ProfilerSupport.STATE_INACTIVE) {
552
                    if (session == null || 
553
                            session.getState() == ProfilerSession.STATE_INACTIVE) 
554
                    {
533
                        start();
555
                        start();
534
                    }
556
                    }
535
                    // end of GF workaround
557
                    // end of GF workaround
Lines 541-554 Link Here
541
                // ***
563
                // ***
542
                do {
564
                do {
543
                    targs = getDeploymentManager().getTargets();
565
                    targs = getDeploymentManager().getTargets();
544
                    if (targs == null && ProfilerSupport.getState() == ProfilerSupport.STATE_PROFILING) {
566
                    session = getProfilerSession();
567
                    if (targs == null && session!= null && 
568
                            session.getState() == ProfilerSession.STATE_PROFILING) 
569
                    {
545
                        try {
570
                        try {
546
                            Thread.sleep(500);
571
                            Thread.sleep(500);
547
                        } catch (InterruptedException ex) {
572
                        } catch (InterruptedException ex) {
548
                            Thread.currentThread().interrupt();
573
                            Thread.currentThread().interrupt();
549
                        }
574
                        }
550
                    }
575
                    }
551
                } while (targs == null && ProfilerSupport.getState() == ProfilerSupport.STATE_PROFILING);
576
                } while (targs == null && session!=null && 
577
                        session.getState() == ProfilerSession.STATE_PROFILING);
552
                // end of GF workaround
578
                // end of GF workaround
553
            } catch(IllegalStateException e) {
579
            } catch(IllegalStateException e) {
554
                LOGGER.log(Level.INFO, null, e);
580
                LOGGER.log(Level.INFO, null, e);
Lines 944-950 Link Here
944
     * not also the target server.
970
     * not also the target server.
945
     */
971
     */
946
    public boolean isProfileSupported() {
972
    public boolean isProfileSupported() {
947
        Profiler profiler = ServerRegistry.getProfiler();
973
        ProfilerProvider profiler = ServerRegistry.getProfilerProvider();
948
        if (profiler == null) {
974
        if (profiler == null) {
949
            return false;
975
            return false;
950
        }
976
        }
Lines 1000-1034 Link Here
1000
        }
1026
        }
1001
    }
1027
    }
1002
    
1028
    
1029
    /* (non-Javadoc)
1030
     * @see org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerStateListener#stateChanged()
1031
     */
1032
    @Override
1033
    public void stateChanged( ProfilerStateEvent event ) {
1034
        int fromState = event.getOldState();
1035
        ProfilerSession session = getProfilerSession();
1036
        if ( session == null ){
1037
            return;
1038
        }
1039
        if ( session.getState() == ProfilerSession.STATE_STOPPING ){
1040
            session.removeProfilerStateListener( this );
1041
        }
1042
        if ( (getStartServer().supportsProfilerStop() ||
1043
                (fromState == ProfilerSession.STATE_RUNNING|| 
1044
                        fromState == ProfilerSession.STATE_PROFILING))
1045
                && session.getState() == ProfilerSession.STATE_STOPPING  )
1046
        {
1047
            ProgressUI progressUI = myProfilerStopUI.get();
1048
            if ( progressUI == null ){
1049
                progressUI = new ProgressUI(NbBundle.getMessage(
1050
                        ServerInstance.class, "MSG_StoppingProfiler", 
1051
                        getDisplayName()), false);
1052
            }
1053
            try {
1054
                doStopServer(progressUI);
1055
            } catch (ServerException ex) {
1056
                String msg = ex.getLocalizedMessage();
1057
                NotifyDescriptor desc = new NotifyDescriptor.Message(msg, 
1058
                        NotifyDescriptor.ERROR_MESSAGE);
1059
                DialogDisplayer.getDefault().notify(desc);
1060
            }
1061
        }
1062
        else {
1063
            refresh();
1064
        }
1065
    }
1066
    
1003
    /** Start the admin server in the profile mode. Show UI feedback. 
1067
    /** Start the admin server in the profile mode. Show UI feedback. 
1004
     * @param settings settings that will be used to start the server
1068
     * @param session profiler session
1005
     *
1069
     *
1006
     * @throws ServerException if the server cannot be started.
1070
     * @throws ServerException if the server cannot be started.
1007
     */
1071
     */
1008
    public void startProfile(ProfilerServerSettings settings, boolean forceRestart, ProgressUI ui) 
1072
    public void startProfile(ProfilerSession session, boolean forceRestart, 
1009
    throws ServerException {
1073
            ProgressUI ui) throws ServerException 
1010
        // check whether another server not already running in profile mode
1074
    {
1011
        // and ask whether it is ok to stop it
1075
        synchronized (myLock) {
1012
        ServerInstance tmpProfiledServerInstance = profiledServerInstance;
1076
            // check whether another server not already running in profile mode
1013
        if (tmpProfiledServerInstance != null && tmpProfiledServerInstance != this) {
1077
            // and ask whether it is ok to stop it
1014
            String msg = NbBundle.getMessage(
1078
            synchronized (session.getProvider()) {
1079
                if (!session.getProvider().canConfigure(session)) {
1080
                    ServerInstance[] serverInstances = ServerRegistry
1081
                            .getInstance().getServerInstances();
1082
                    StringBuilder builder = new StringBuilder();
1083
                    for (ServerInstance serverInstance : serverInstances) {
1084
                        ProfilerSession profiler = serverInstance
1085
                                .getProfilerSession();
1086
                        if (profiler != null
1087
                                && profiler.getProvider() == session
1088
                                        .getProvider())
1089
                        {
1090
                            builder.append(serverInstance.getDisplayName());
1091
                            builder.append(", "); // NOI18N
1092
                        }
1093
                    }
1094
                    if (builder.length() > 0) {
1095
                        builder = builder.delete(builder.length() - 2, builder
1096
                                .length());
1097
                        String msg = NbBundle.getMessage(ServerInstance.class,
1098
                                "MSG_AnotherServerProfiling", // NOI18N
1099
                                builder.toString());
1100
                        NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
1101
                                msg, NotifyDescriptor.OK_CANCEL_OPTION);
1102
                        if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.CANCEL_OPTION)
1103
                        {
1104
                            // start in profile mode has been cancelled
1105
                            String err = NbBundle.getMessage(
1015
                                    ServerInstance.class,
1106
                                    ServerInstance.class,
1016
                                    "MSG_AnotherServerProfiling",
1107
                                    "MSG_ProfilingCancelled", // NOI18N
1017
                                    tmpProfiledServerInstance.getDisplayName());
1108
                                    getDisplayName());
1018
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(msg, NotifyDescriptor.OK_CANCEL_OPTION);
1109
                            throw new ServerException(err);
1019
            if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.CANCEL_OPTION) {
1110
                        }
1020
                // start in profile mode has been cancelled
1111
                    }
1021
                String err = NbBundle.getMessage(ServerInstance.class, "MSG_ProfilingCancelled", getDisplayName());
1112
                }
1022
                throw new ServerException(err);
1113
                try {
1114
                    setServerState(STATE_WAITING);
1115
                    // target == null - admin server
1116
                    _startProfile(null, session, forceRestart, ui);
1117
                }
1118
                finally {
1119
                    refresh();
1120
                }
1023
            }
1121
            }
1024
        }
1122
        }
1025
        try {
1026
            setServerState(STATE_WAITING);
1027
            // target == null - admin server
1028
            _startProfile(null, settings, forceRestart, ui);
1029
        } finally {
1030
            refresh();
1031
        }
1032
    }
1123
    }
1033
    
1124
    
1034
    /** Restart the admin server in the mode the server was running in before. 
1125
    /** Restart the admin server in the mode the server was running in before. 
Lines 1039-1046 Link Here
1039
    public void restart(ProgressUI ui) throws ServerException {
1130
    public void restart(ProgressUI ui) throws ServerException {
1040
        try {
1131
        try {
1041
            setServerState(STATE_WAITING);
1132
            setServerState(STATE_WAITING);
1133
            ProfilerSession session = mySession.get();
1042
            boolean inDebug = isDebuggable(null);
1134
            boolean inDebug = isDebuggable(null);
1043
            boolean inProfile = profiledServerInstance == this;
1135
            boolean inProfile = session!=null;
1044
            boolean stopped = true;
1136
            boolean stopped = true;
1045
            
1137
            
1046
            if (inProfile || isReallyRunning() || isSuspended()) {
1138
            if (inProfile || isReallyRunning() || isSuspended()) {
Lines 1049-1055 Link Here
1049
            if (stopped) {
1141
            if (stopped) {
1050
                // restart in the mode the server was running in before
1142
                // restart in the mode the server was running in before
1051
                if (inProfile) {
1143
                if (inProfile) {
1052
                    _startProfile(null, profilerSettings, true, ui);
1144
                    _startProfile(null, session, true, ui);
1053
                } else if (inDebug) {
1145
                } else if (inDebug) {
1054
                    startDebugTarget(null, ui);
1146
                    startDebugTarget(null, ui);
1055
                } else {
1147
                } else {
Lines 1068-1074 Link Here
1068
    public void stop(ProgressUI ui) throws ServerException {
1160
    public void stop(ProgressUI ui) throws ServerException {
1069
        try {
1161
        try {
1070
            setServerState(STATE_WAITING);
1162
            setServerState(STATE_WAITING);
1071
            if (profiledServerInstance == this || isReallyRunning() || isSuspended()) {
1163
            if (getProfilerSession()!=null || isReallyRunning() || isSuspended()) {
1072
                _stop(ui);
1164
                _stop(ui);
1073
            }
1165
            }
1074
            debugInfo.clear();
1166
            debugInfo.clear();
Lines 1155-1166 Link Here
1155
     *
1247
     *
1156
     * @throws ServerException if the server cannot be started.
1248
     * @throws ServerException if the server cannot be started.
1157
     */
1249
     */
1158
    public boolean startProfile(final ProfilerServerSettings settings, boolean forceRestart, Deployment.Logger logger) {
1250
    public boolean startProfile(final ProfilerSession session , 
1159
        String title = NbBundle.getMessage(ServerInstance.class, "LBL_StartServerInProfileMode", getDisplayName());
1251
            boolean forceRestart, Deployment.Logger logger) 
1252
    {
1253
        String title = NbBundle.getMessage(ServerInstance.class, 
1254
                "LBL_StartServerInProfileMode", getDisplayName());      // NOI18N
1160
        ProgressUI ui = new ProgressUI(title, false, logger);
1255
        ProgressUI ui = new ProgressUI(title, false, logger);
1161
        try {
1256
        try {
1162
            ui.start();
1257
            ui.start();
1163
            startProfile(settings, forceRestart, ui);
1258
            startProfile(session, forceRestart, ui);
1164
            return true;
1259
            return true;
1165
        } catch (ServerException ex) {
1260
        } catch (ServerException ex) {
1166
            return false;
1261
            return false;
Lines 1385-1434 Link Here
1385
        }
1480
        }
1386
    }
1481
    }
1387
    
1482
    
1388
    /** start server in the profile mode */
1483
    /* start server in the profile mode 
1389
    private void _startProfile(
1484
     *
1390
                                    Target target, 
1485
     * This method suppose to be called under session.getProvider() lock
1391
                                    ProfilerServerSettings settings,
1486
     */
1392
                                    boolean forceRestart,
1487
    private void _startProfile(Target target, ProfilerSession session,
1393
                                    ProgressUI ui) throws ServerException {
1488
            boolean forceRestart,ProgressUI ui) throws ServerException 
1394
        ProfilerServerSettings  tmpProfilerSettings;
1489
    {
1395
        synchronized (this) {
1490
        ProfilerSession currentSession = mySession.get();
1396
            tmpProfilerSettings = profilerSettings;
1491
        
1492
        if (session == null) {
1493
            // this should not occur, but better make sure
1494
            throw new ServerException(NbBundle.getMessage(ServerInstance.class, 
1495
                    "MSG_ProfilerNotRegistered"));                  // NOI18N
1397
        }
1496
        }
1398
        ServerInstance tmpProfiledServerInstance = profiledServerInstance;
1497
        
1399
        if (tmpProfiledServerInstance == this && !forceRestart && settings.equals(tmpProfilerSettings)) {
1498
        if (  !forceRestart && session.equals( currentSession )) 
1499
        {
1400
            return; // server is already runnning in profile mode, no need to restart the server
1500
            return; // server is already runnning in profile mode, no need to restart the server
1401
        }
1501
        }
1402
        if (tmpProfiledServerInstance != null && tmpProfiledServerInstance != this) {
1502
        
1403
            // another server currently running in profiler mode
1503
        if( !session.getProvider().canConfigure(session) ) 
1404
            tmpProfiledServerInstance.stop(ui);
1504
        {
1405
            profiledServerInstance = null;
1505
            ServerInstance[] serverInstances = ServerRegistry.getInstance()
1406
        }
1506
                .getServerInstances();
1407
        if (profiledServerInstance == this || isReallyRunning() || isDebuggable(target)) {
1507
            for (ServerInstance serverInstance : serverInstances) {
1408
            _stop(ui);
1508
                    ProfilerSession profiler = serverInstance
1409
            debugInfo.clear();
1509
                        .getProfilerSession();
1410
            profiledServerInstance = null;
1510
                    if (profiler != null && profiler.getProvider() == 
1511
                        session.getProvider()) 
1512
                    {
1513
                        serverInstance._stop(ui);
1514
                        if ( session.getProvider().canConfigure(session) ){
1515
                            break;
1516
                        }
1517
                    }
1518
            }
1411
        }
1519
        }
1412
        
1520
        
1413
        Profiler profiler = ServerRegistry.getProfiler();
1521
        if ( !session.getProvider().canConfigure( session )){
1414
        if (profiler == null) {
1522
            throw new ServerException(NbBundle.getMessage(ServerInstance.class, 
1415
            // this should not occur, but better make sure
1523
                "MSG_ProfilerNoNewSession"));           // NOI18N
1416
            throw new ServerException(NbBundle.getMessage(ServerInstance.class, "MSG_ProfilerNotRegistered"));
1417
        }
1524
        }
1418
        profiler.notifyStarting();
1525
        
1419
        ProgressObject po = getStartServer().startProfiling(target, settings);
1526
        ProfilerServerSettings settings = session.configureSession();
1527
        session.addProfilerStateListener( this );
1528
        session.notifyStarting();
1529
        ProgressObject po = getStartServer().startProfiling(target, settings, 
1530
                session);
1420
        try {
1531
        try {
1421
            boolean completedSuccessfully = ProgressObjectUtil.trackProgressObject(ui, po, DEFAULT_TIMEOUT);
1532
            boolean completedSuccessfully = ProgressObjectUtil.
1533
                trackProgressObject(ui, po, DEFAULT_TIMEOUT);
1422
            if (!completedSuccessfully) {
1534
            if (!completedSuccessfully) {
1423
                throw new ServerException(po.getDeploymentStatus().getMessage());
1535
                throw new ServerException(po.getDeploymentStatus().getMessage());
1424
            }
1536
            }
1425
        } catch (TimedOutException e) {
1537
        } catch (TimedOutException e) {
1426
            String msg = NbBundle.getMessage(ServerInstance.class, "MSG_StartProfileTimeout", getDisplayName());
1538
            String msg = NbBundle.getMessage(ServerInstance.class, 
1539
                    "MSG_StartProfileTimeout", getDisplayName());
1427
            throw new ServerException(msg);
1540
            throw new ServerException(msg);
1428
        }
1541
        }
1429
        profiledServerInstance = this;
1542
        mySession.set( session );
1430
        synchronized (this) {
1543
        synchronized (this) {
1431
            profilerSettings = settings;
1432
            managerStartedByIde = true;
1544
            managerStartedByIde = true;
1433
//            coTarget = null;
1545
//            coTarget = null;
1434
//            targets = null;
1546
//            targets = null;
Lines 1437-1454 Link Here
1437
    }
1549
    }
1438
    
1550
    
1439
    /** Tell the profiler to shutdown */
1551
    /** Tell the profiler to shutdown */
1440
    private void shutdownProfiler(ProgressUI ui) throws ServerException {
1552
    private void shutdownProfiler(ProfilerSession session , ProgressUI ui) 
1441
        ui.progress(NbBundle.getMessage(ServerInstance.class, "MSG_StoppingProfiler"));
1553
        throws ServerException 
1442
        Profiler profiler = ServerRegistry.getProfiler();
1554
    {
1443
        if (profiler != null) {
1555
        ui.progress(NbBundle.getMessage(ServerInstance.class, 
1444
            ProgressObject po = profiler.shutdown();
1556
                "MSG_StoppingProfiler"));                   // NOI18N
1557
        if (session != null) {
1558
            ProgressObject po = session.notifyStop();
1445
            try {
1559
            try {
1446
                boolean completedSuccessfully = ProgressObjectUtil.trackProgressObject(ui, po, getShutdownTimeout());
1560
                boolean completedSuccessfully = ProgressObjectUtil.
1561
                    trackProgressObject(ui, po, getShutdownTimeout());
1447
                if (!completedSuccessfully) {
1562
                if (!completedSuccessfully) {
1448
                    throw new ServerException(po.getDeploymentStatus().getMessage());
1563
                    throw new ServerException(po.getDeploymentStatus().getMessage());
1449
                }
1564
                }
1450
            } catch (TimedOutException e) {
1565
            } catch (TimedOutException e) {
1451
                String msg = NbBundle.getMessage(ServerInstance.class, "MSG_ProfilerShutdownTimeout");
1566
                String msg = NbBundle.getMessage(ServerInstance.class, 
1567
                        "MSG_ProfilerShutdownTimeout");         // NOI18N
1452
                throw new ServerException(msg);
1568
                throw new ServerException(msg);
1453
            }
1569
            }
1454
        }
1570
        }
Lines 1457-1508 Link Here
1457
    // stopDeploymentManager
1573
    // stopDeploymentManager
1458
    private void _stop(ProgressUI ui) throws ServerException {
1574
    private void _stop(ProgressUI ui) throws ServerException {
1459
        // if the server is started in profile mode, deattach profiler first
1575
        // if the server is started in profile mode, deattach profiler first
1460
        if (profiledServerInstance == this) {
1576
        ProfilerSession session = getProfilerSession();
1461
            shutdownProfiler(ui);
1577
        if (session != null) {
1462
            profiledServerInstance = null;
1578
            myProfilerStopUI.set( ui );
1579
            shutdownProfiler(session, ui);
1580
            mySession.set(null);
1581
            myProfilerStopUI.set( null );
1582
            return;
1463
        }
1583
        }
1464
        synchronized (this) {
1584
        doStopServer(ui);
1465
            // if the server is suspended, the debug session has to be terminated first
1585
    }
1466
            if (isSuspended()) {
1586
1467
                Target target = _retrieveTarget(null);
1587
    private void doStopServer( ProgressUI ui ) throws ServerException {
1468
                ServerDebugInfo sdi = getServerDebugInfo(target);
1588
        synchronized (myLock) {
1469
                Session[] sessions = DebuggerManager.getDebuggerManager().getSessions();
1589
            // if the server is suspended, the debug session has to be
1470
                for (int i = 0; i < sessions.length; i++) {
1590
            // terminated first
1471
                    Session s = sessions[i];
1591
            synchronized (this) {
1472
                    if (s != null) {
1592
                if (isSuspended()) {
1473
                        AttachingDICookie attCookie = (AttachingDICookie)s.lookupFirst(null, AttachingDICookie.class);
1593
                    Target target = _retrieveTarget(null);
1474
                        if (attCookie != null) {
1594
                    ServerDebugInfo sdi = getServerDebugInfo(target);
1475
                            if (sdi.getTransport().equals(ServerDebugInfo.TRANSPORT_SHMEM)) {
1595
                    Session[] sessions = DebuggerManager.getDebuggerManager()
1476
                                String shmem = attCookie.getSharedMemoryName();
1596
                            .getSessions();
1477
                                if (shmem != null && shmem.equalsIgnoreCase(sdi.getShmemName())) {
1597
                    for (int i = 0; i < sessions.length; i++) {
1478
                                    s.kill();
1598
                        Session s = sessions[i];
1599
                        if (s != null) {
1600
                            AttachingDICookie attCookie = (AttachingDICookie) s
1601
                                    .lookupFirst(null, AttachingDICookie.class);
1602
                            if (attCookie != null) {
1603
                                if (sdi.getTransport().equals(
1604
                                        ServerDebugInfo.TRANSPORT_SHMEM))
1605
                                {
1606
                                    String shmem = attCookie
1607
                                            .getSharedMemoryName();
1608
                                    if (shmem != null
1609
                                            && shmem.equalsIgnoreCase(sdi
1610
                                                    .getShmemName()))
1611
                                    {
1612
                                        s.kill();
1613
                                    }
1479
                                }
1614
                                }
1480
                            } else {
1615
                                else {
1481
                                String host = attCookie.getHostName();
1616
                                    String host = attCookie.getHostName();
1482
                                if (host != null && isSameHost(host, sdi.getHost())
1617
                                    if (host != null
1483
                                        && attCookie.getPortNumber() == sdi.getPort()) {
1618
                                            && isSameHost(host, sdi.getHost())
1484
                                    s.kill();
1619
                                            && attCookie.getPortNumber() == sdi
1620
                                                    .getPort())
1621
                                    {
1622
                                        s.kill();
1623
                                    }
1485
                                }
1624
                                }
1486
                            }
1625
                            }
1487
                        }
1626
                        }
1488
                    }
1627
                    }
1489
                }
1628
                }
1490
            }
1629
            }
1630
            ProgressObject po = getStartServer().stopDeploymentManager();
1631
            try {
1632
                boolean completedSuccessfully = ProgressObjectUtil
1633
                        .trackProgressObject(ui, po, getShutdownTimeout());
1634
                if (!completedSuccessfully) {
1635
                    throw new ServerException(po.getDeploymentStatus()
1636
                            .getMessage());
1637
                }
1638
            }
1639
            catch (TimedOutException e) {
1640
                String msg = NbBundle.getMessage(ServerInstance.class,
1641
                        "MSG_StopServerTimeout", getDisplayName()); // NOI18N
1642
                throw new ServerException(msg);
1643
            }
1644
            synchronized ( this ) {
1645
                managerStartedByIde = false;
1646
            }
1647
            refresh();
1648
            reset();
1491
        }
1649
        }
1492
        ProgressObject po = getStartServer().stopDeploymentManager();
1493
        try {
1494
            boolean completedSuccessfully = ProgressObjectUtil.trackProgressObject(ui, po, getShutdownTimeout());
1495
            if (!completedSuccessfully) {
1496
                throw new ServerException(po.getDeploymentStatus().getMessage());
1497
            }
1498
        } catch (TimedOutException e) {
1499
            String msg = NbBundle.getMessage(ServerInstance.class, "MSG_StopServerTimeout", getDisplayName());
1500
            throw new ServerException(msg);
1501
        }
1502
        synchronized (this) {
1503
            managerStartedByIde = false;
1504
        }
1505
        reset();
1506
    }
1650
    }
1507
    
1651
    
1508
    private void _start(Target target, ProgressUI ui) throws ServerException {
1652
    private void _start(Target target, ProgressUI ui) throws ServerException {
Lines 1672-1677 Link Here
1672
        return sdi;
1816
        return sdi;
1673
    }
1817
    }
1674
    
1818
    
1819
    private ProfilerSession getProfilerSession(){
1820
        return mySession.get();
1821
    }
1822
    
1675
    private Target _retrieveTarget(Target target) {
1823
    private Target _retrieveTarget(Target target) {
1676
        StartServer ss = getStartServer();
1824
        StartServer ss = getStartServer();
1677
        if (ss == null) {
1825
        if (ss == null) {
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java (-3 / +28 lines)
Lines 67-73 Link Here
67
import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
67
import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
68
import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory;
68
import org.netbeans.modules.j2ee.deployment.plugins.spi.OptionalDeploymentManagerFactory;
69
import org.netbeans.modules.j2ee.deployment.plugins.spi.ServerInitializationException;
69
import org.netbeans.modules.j2ee.deployment.plugins.spi.ServerInitializationException;
70
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
70
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerProvider;
71
import org.openide.filesystems.FileChangeAdapter;
71
import org.openide.filesystems.FileChangeAdapter;
72
import org.openide.filesystems.FileEvent;
72
import org.openide.filesystems.FileEvent;
73
import org.openide.filesystems.FileObject;
73
import org.openide.filesystems.FileObject;
Lines 618-624 Link Here
618
    }
618
    }
619
619
620
    /** Return profiler if any is registered in the IDE, null otherwise. */
620
    /** Return profiler if any is registered in the IDE, null otherwise. */
621
    public static Profiler getProfiler() {
621
    public static ProfilerProvider getProfilerProvider() {
622
        return (Profiler)Lookup.getDefault().lookup(Profiler.class);
622
        /*
623
         * TODO: this code could be changed to get provider id which 
624
         * is set up in NetBeans preferences .
625
         * This id should be an argument instead of <code>null</code>.
626
         * I.e. NBPreferences.forModule().....
627
         */
628
        return getProfilerProvider( null);
629
    }
630
    
631
    public static ProfilerProvider getProfilerProvider(Object id ) {
632
        Collection<? extends ProfilerProvider> providers = Lookup.getDefault().
633
            lookupAll(ProfilerProvider.class);
634
        ProfilerProvider found = null;
635
        for (ProfilerProvider provider : providers) {
636
            if ( provider.isApplicable(id)){
637
                if ( found == null ){
638
                    found = provider;
639
                }
640
                else {
641
                    throw new IllegalArgumentException(NbBundle.getMessage(
642
                            ServerRegistry.class, "ERR_MultipleProviders" ,
643
                            id, found.getClass(), provider.getClass()));
644
                }
645
            }
646
        }
647
        return found;
623
    }
648
    }
624
}
649
}
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/TargetServer.java (-5 / +9 lines)
Lines 79-93 Link Here
79
import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener.Artifact;
79
import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener.Artifact;
80
import org.netbeans.modules.j2ee.deployment.execution.ModuleConfigurationProvider;
80
import org.netbeans.modules.j2ee.deployment.execution.ModuleConfigurationProvider;
81
import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI;
81
import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI;
82
import org.netbeans.modules.j2ee.deployment.plugins.api.AppChangeDescriptor;
83
import org.netbeans.modules.j2ee.deployment.plugins.api.DeploymentChangeDescriptor;
82
import org.netbeans.modules.j2ee.deployment.plugins.api.DeploymentChangeDescriptor;
84
import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment;
83
import org.netbeans.modules.j2ee.deployment.plugins.spi.IncrementalDeployment;
85
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
84
import org.netbeans.modules.j2ee.deployment.plugins.spi.config.ModuleConfiguration;
86
import org.netbeans.modules.j2ee.deployment.plugins.spi.TargetModuleIDResolver;
85
import org.netbeans.modules.j2ee.deployment.plugins.spi.TargetModuleIDResolver;
87
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
86
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
88
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
87
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerProvider;
88
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerSession;
89
import org.openide.util.Exceptions;
89
import org.openide.util.Exceptions;
90
import org.openide.util.Lookup;
91
90
92
/**
91
/**
93
 * Encapsulates a set of ServerTarget(s), provides a wrapper for deployment
92
 * Encapsulates a set of ServerTarget(s), provides a wrapper for deployment
Lines 497-504 Link Here
497
                    break;
496
                    break;
498
                }
497
                }
499
                case PROFILE: {
498
                case PROFILE: {
500
                    ProfilerServerSettings settings = Lookup.getDefault().lookup(Profiler.class).getSettings(instance.getUrl(), false);
499
                    ProfilerProvider provider = ServerRegistry.getProfilerProvider();
501
                    instance.startProfile(settings, false, ui);
500
                    ProfilerServerSettings settings = provider.getDefaultServerSettings(
501
                                instance.getUrl(), false);
502
                    ProfilerSession session = provider.getSession(settings);
503
                    if ( session != null ){
504
                        instance.startProfile(session, false, ui);
505
                    }
502
                    break;
506
                    break;
503
                }
507
                }
504
                case RUN: {
508
                case RUN: {
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ui/actions/ProfileAction.java (-5 / +8 lines)
Lines 47-53 Link Here
47
import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
47
import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
48
import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI;
48
import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI;
49
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
49
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
50
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
50
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerProvider;
51
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerSession;
51
import org.openide.DialogDisplayer;
52
import org.openide.DialogDisplayer;
52
import org.openide.NotifyDescriptor;
53
import org.openide.NotifyDescriptor;
53
import org.openide.nodes.Node;
54
import org.openide.nodes.Node;
Lines 91-111 Link Here
91
        }
92
        }
92
        final ServerInstance si = (ServerInstance)nodes[0].getCookie(ServerInstance.class);
93
        final ServerInstance si = (ServerInstance)nodes[0].getCookie(ServerInstance.class);
93
        if (si != null) {
94
        if (si != null) {
94
            Profiler profiler = ServerRegistry.getProfiler();
95
            ProfilerProvider provider = ServerRegistry.getProfilerProvider();
95
            if (profiler == null) {
96
            if (provider == null) {
96
                return;
97
                return;
97
            }
98
            }
98
            final ProfilerServerSettings settings = profiler.getSettings(si.getUrl());
99
            ProfilerServerSettings settings = provider.getDefaultServerSettings(
100
                    si.getUrl(), true );
99
            if (settings == null) {
101
            if (settings == null) {
100
                return;
102
                return;
101
            }
103
            }
104
            final ProfilerSession session = provider.getSession(settings);
102
            RequestProcessor.getDefault().post(new Runnable() {
105
            RequestProcessor.getDefault().post(new Runnable() {
103
                public void run() {
106
                public void run() {
104
                    String title = NbBundle.getMessage(DebugAction.class, "LBL_Profiling", si.getDisplayName());
107
                    String title = NbBundle.getMessage(DebugAction.class, "LBL_Profiling", si.getDisplayName());
105
                    ProgressUI progressUI = new ProgressUI(title, false);
108
                    ProgressUI progressUI = new ProgressUI(title, false);
106
                    try {
109
                    try {
107
                        progressUI.start();
110
                        progressUI.start();
108
                        si.startProfile(settings, false, progressUI);
111
                        si.startProfile(session, false, progressUI);
109
                    } catch (ServerException ex) {
112
                    } catch (ServerException ex) {
110
                        String msg = ex.getLocalizedMessage();
113
                        String msg = ex.getLocalizedMessage();
111
                        NotifyDescriptor desc = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
114
                        NotifyDescriptor desc = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/plugins/spi/StartServer.java (-1 / +23 lines)
Lines 46-51 Link Here
46
import javax.enterprise.deploy.spi.status.ProgressObject;
46
import javax.enterprise.deploy.spi.status.ProgressObject;
47
import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo;
47
import org.netbeans.modules.j2ee.deployment.plugins.api.ServerDebugInfo;
48
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
48
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
49
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerSession;
49
50
50
/**
51
/**
51
 * Server lifecycle services from the IDE.  J2eeserver will use these
52
 * Server lifecycle services from the IDE.  J2eeserver will use these
Lines 250-256 Link Here
250
     *
251
     *
251
     * @since 1.9
252
     * @since 1.9
252
     */
253
     */
253
    public ProgressObject startProfiling(Target target, ProfilerServerSettings settings) {
254
    public ProgressObject startProfiling(Target target, 
255
            ProfilerServerSettings settings, ProfilerSession session ) 
256
    {
254
        throw new UnsupportedOperationException("Starting in profile mode is not supported by this server."); // NIO18N
257
        throw new UnsupportedOperationException("Starting in profile mode is not supported by this server."); // NIO18N
255
    }
258
    }
256
    
259
    
Lines 269-272 Link Here
269
    public boolean needsRestart(Target target) {
272
    public boolean needsRestart(Target target) {
270
         return false;
273
         return false;
271
    }
274
    }
275
276
    /**
277
     * Returns <code>true</code> if server plugin is able to stop profiler agent
278
     * when server is not yet started.
279
     * 
280
     * Server will be stopped via {@link #stopDeploymentManager()} when 
281
     * it was started on its JVM. But usually it cannot be stopped via 
282
     * mentioned method when Profiler agent is in blocking state 
283
     * ( agent is loaded  , listen its port , but server is not started ). 
284
     * In this case Profiler agent is just killed by implementation of
285
     * profiler API. But sometimes this kill could be not enough.
286
     * In the latter case this method should returns <code>true</code>.
287
     * As result method {@link #stopDeploymentManager()} will be called  .
288
     *     
289
     * @return <code>true</code> if server plugin wants to add profiler agent stop logic
290
     */
291
    public boolean supportsProfilerStop() {
292
        return false;
293
    }
272
}
294
}
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/api/ProfilerServerSettings.java (-3 / +46 lines)
Lines 42-62 Link Here
42
package org.netbeans.modules.j2ee.deployment.profiler.api;
42
package org.netbeans.modules.j2ee.deployment.profiler.api;
43
43
44
import java.util.Arrays;
44
import java.util.Arrays;
45
import java.util.HashMap;
45
import java.util.List;
46
import java.util.List;
47
import java.util.Map;
48
46
import org.netbeans.api.java.platform.JavaPlatform;
49
import org.netbeans.api.java.platform.JavaPlatform;
47
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
48
import org.openide.filesystems.FileUtil;
51
import org.openide.filesystems.FileUtil;
49
52
53
50
/**
54
/**
51
 * Settings that will be used for profiled server startup.
55
 * Settings that will be used for profiled server startup.
52
 *
56
 *
53
 * @author sherold
57
 * @author sherold
54
 */
58
 */
55
public final class ProfilerServerSettings {
59
public final class ProfilerServerSettings  {
56
60
57
    private JavaPlatform    javaPlatform;
61
    private JavaPlatform    javaPlatform;
58
    private String[]        jvmArgs;
62
    private String[]        jvmArgs;
59
    private String[]        env;
63
    private String[]        env;
64
    private Map        myProperties;
60
65
61
    /**
66
    /**
62
     * Creates new ProfilerServerSettings.
67
     * Creates new ProfilerServerSettings.
Lines 67-73 Link Here
67
     * @param env          array of <code>name=value</code> pairs of extra variables 
72
     * @param env          array of <code>name=value</code> pairs of extra variables 
68
     *                     to be set for profiled server environment.
73
     *                     to be set for profiled server environment.
69
     */
74
     */
70
    public ProfilerServerSettings(JavaPlatform javaPlatform, String[] jvmArgs, String[] env) {
75
    public ProfilerServerSettings(JavaPlatform javaPlatform, String[] jvmArgs, 
76
            String[] env, Map properties ) 
77
    {
71
        if (javaPlatform == null) {
78
        if (javaPlatform == null) {
72
            throw new NullPointerException("The javaPlatform argument must not be null.");  // NOI18N
79
            throw new NullPointerException("The javaPlatform argument must not be null.");  // NOI18N
73
        }
80
        }
Lines 77-85 Link Here
77
        if (env == null) {
84
        if (env == null) {
78
            throw new NullPointerException("The env argument must not be null.");           // NOI18N
85
            throw new NullPointerException("The env argument must not be null.");           // NOI18N
79
        }
86
        }
87
        if ( properties == null ){
88
            properties = new HashMap();
89
        }
80
        this.javaPlatform   = javaPlatform;
90
        this.javaPlatform   = javaPlatform;
81
        this.jvmArgs        = jvmArgs;
91
        this.jvmArgs        = jvmArgs;
82
        this.env            = env;
92
        this.env            = env;
93
        myProperties = properties;
83
    }
94
    }
84
95
85
    /**
96
    /**
Lines 90-96 Link Here
90
    public JavaPlatform getJavaPlatform() {
101
    public JavaPlatform getJavaPlatform() {
91
        return javaPlatform;
102
        return javaPlatform;
92
    }
103
    }
93
104
    
94
    /**
105
    /**
95
     * Gets the extra arguments that will be used for starting the profiled server.
106
     * Gets the extra arguments that will be used for starting the profiled server.
96
     *
107
     *
Lines 100-105 Link Here
100
    public String[] getJvmArgs() {
111
    public String[] getJvmArgs() {
101
        return jvmArgs;
112
        return jvmArgs;
102
    }
113
    }
114
    
115
    /**
116
     * Sets jvm arguments . These arguments are originally passed to constructor
117
     * of this settings and could be changed by profiler provider for new session
118
     * via this method.
119
     * 
120
     * @param args new arguments
121
     */
122
    public void setJvmArgs( String[] args ){
123
        jvmArgs = args;
124
    }
103
125
104
    /**
126
    /**
105
     * Gets extra variables that will be set for profiled server environment.
127
     * Gets extra variables that will be set for profiled server environment.
Lines 112-117 Link Here
112
    }
134
    }
113
    
135
    
114
    /**
136
    /**
137
     * Sets environment variables . These variables are originally passed to constructor
138
     * of this settings and could be changed by profiler provider for new session
139
     * via this method.
140
     * 
141
     * @param envp new variables
142
     */
143
    public void setEnv( String[] envp ) {
144
        env = envp;
145
    }
146
    
147
    /**
148
     * Gets properties which can be used for store/retrieve information
149
     * between J2EE server runner and profiler session.
150
     * 
151
     * @return settings properties
152
     */
153
    public Map getProperties(){
154
        return myProperties;
155
    }
156
    
157
    /**
115
     * Tests this ProfilerServerSettings for equality with the given object.
158
     * Tests this ProfilerServerSettings for equality with the given object.
116
     *
159
     *
117
     * @param o The object to be compared with this ProfilerServerSettings.
160
     * @param o The object to be compared with this ProfilerServerSettings.
(-)3358e7eefa36 (+73 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.j2ee.deployment.profiler.api;
42
43
import org.netbeans.modules.j2ee.deployment.profiler.spi.ProfilerSession;
44
45
46
/**
47
 * @author ads
48
 *
49
 */
50
public final class ProfilerStateEvent {
51
52
    public ProfilerStateEvent( ProfilerSession session , int oldState, int newState){
53
        myOldState = oldState;
54
        myNewState = newState;
55
        mySession = session;
56
    }
57
    
58
    public int getOldState(){
59
        return myOldState;
60
    }
61
    
62
    public int getNewState(){
63
        return myNewState;
64
    }
65
    
66
    public ProfilerSession getSession(){
67
        return mySession;
68
    }
69
    
70
    private int myOldState;
71
    private int myNewState;
72
    private ProfilerSession mySession;
73
}
(-)3358e7eefa36 (+57 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.j2ee.deployment.profiler.api;
42
43
44
45
/**
46
 * @author ads
47
 *
48
 */
49
public interface ProfilerStateListener {
50
51
    /**
52
     * Notify about changed state.
53
     *
54
     * @param event profiler state event
55
     */
56
    void stateChanged( ProfilerStateEvent event );
57
}
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/api/ProfilerSupport.java (-93 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.j2ee.deployment.profiler.api;
43
44
import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
45
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
46
47
/**
48
 * Allows to determine current state of a Profiler registered in the default Lookup.
49
 *
50
 * @author sherold
51
 */
52
public final class ProfilerSupport {
53
54
    /**
55
     * The Profiler agent isn't running.
56
     */
57
    public static final int STATE_INACTIVE  = 0;
58
59
    /**
60
     * The Profiler agent is starting to STATE_BLOCKING or STATE_RUNNING state,
61
     * target JVM isn't running.
62
     */
63
    public static final int STATE_STARTING  = 1;
64
    
65
    /**
66
     * The Profiler agent is running and ready for the Profiler to connect, target
67
     * JVM is blocked.
68
     */
69
    public static final int STATE_BLOCKING  = 2;
70
    
71
    /**
72
     * The Profiler agent is running and ready for the Profiler to connect, target
73
     * JVM is running.
74
     */
75
    public static final int STATE_RUNNING   = 3;
76
    
77
    /**
78
     * The Profiler agent is running and connected to Profiler, target JVM is running.
79
     */
80
    public static final int STATE_PROFILING = 4;
81
    
82
    /**
83
     * Returns the current state of a Profiler registered into Lookup.
84
     *
85
     * @return the current profiler state or <code>STATE_INACTIVE</code> if no 
86
     *         Profiler is registered in the default Lookup.
87
     */
88
    public static int getState() {
89
        Profiler profiler = ServerRegistry.getProfiler();
90
        return profiler == null ? STATE_INACTIVE 
91
                                : profiler.getState();
92
    }
93
}
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/profiler/spi/Profiler.java (-114 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.j2ee.deployment.profiler.spi;
43
44
import java.util.Map;
45
import javax.enterprise.deploy.spi.status.ProgressObject;
46
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
47
48
/**
49
 * Profiler has to implement this interface and register it in the default Lookup.
50
 *
51
 * @author sherold
52
 */
53
public interface Profiler {
54
55
    /**
56
     * Inform the profiler that some server is starting in the profile mode. It
57
     * allows the Profiler to correctly detect STATE_STARTING.
58
     */
59
    void notifyStarting();
60
    
61
    /**
62
     * This method is used from the <code>nbstartprofiledserver</code>
63
     * task to connect the Profiler to a server ready for profiling.
64
     *
65
     * @param projectProperties properties of project the <code>nbstartprofiledserver</code>
66
     *                          ant task was started from.
67
     *
68
     * @return <code>true</code> if the Profiler successfully attached to the server.
69
     */
70
    boolean attachProfiler(Map projectProperties);
71
    
72
    /**
73
     * This method is used from the Runtime tab to obtain settings for starting 
74
     * the server. It displays dialog and let the user choose required mode 
75
     * (direct/dynamic attach) and other settings for the server startup.
76
     *
77
     * @param   serverInstanceID ID of the server instance that is going to be started
78
     *
79
     * @return  required settings or <code>null</code> if user cancelled starting 
80
     *          the server.
81
     */
82
    ProfilerServerSettings getSettings(String serverInstanceID);
83
84
    /**
85
     * This method is used from the Runtime tab to obtain settings for starting
86
     * the server. It displays dialog and let the user choose required mode
87
     * (direct/dynamic attach) and other settings for the server startup.
88
     *
89
     * @param   serverInstanceID ID of the server instance that is going to be started
90
     * @param   verbose Whether to show the informational dialog
91
     *
92
     * @return  required settings or <code>null</code> if user cancelled starting
93
     *          the server.
94
     */
95
    ProfilerServerSettings getSettings(String serverInstanceID, boolean verbose);
96
    
97
    /**
98
     * Returns state of Profiler agent instance started from the IDE. It detects 
99
     * possible response from an unknown (not started from the IDE) Profiler
100
     * agent, in this case it returns STATE_INACTIVE.
101
     *
102
     * @return state of Profiler agent instance.
103
     */
104
    int getState();
105
    
106
    /**
107
     * Stops execution of the application (its JVM) currently being profiled.
108
     * Shutdown is performed by the Profiler agent when in STATE_BLOCKED, STATE_RUNNING
109
     * or STATE_PROFILING state.
110
     *
111
     * @return object used to monitor progress of shutdown.
112
     */
113
    ProgressObject shutdown();
114
}
(-)3358e7eefa36 (+99 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.j2ee.deployment.profiler.spi;
42
43
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
44
45
46
/**
47
 * @author ads
48
 *
49
 */
50
public interface ProfilerProvider {
51
52
    /**
53
     * Tests whether provider is applicable for given <code>id</code>.
54
     * Different providers should support different identifiers.
55
     * Single identifier support is not required for one provider.  
56
     * 
57
     * @param id profiler provider id
58
     * @return <code>true</code> if provider supports <code>id</code>
59
     */
60
    boolean isApplicable( Object id );
61
    
62
    /**
63
     * Gets profiler session for given <code>settings</code>.
64
     * 
65
     * @param settings settings which is used for server instance start in profile mode 
66
     * @return profiler server session  
67
     */
68
    ProfilerSession getSession( ProfilerServerSettings settings ); 
69
    
70
71
    /**
72
     * This method is used from the Runtime tab to obtain settings for starting
73
     * the server. It displays dialog if <code>verbose</code> is true 
74
     * and let the user choose required mode (direct/dynamic attach) and 
75
     * other settings for the server startup.
76
     *
77
     * @param   serverInstanceID ID of the server instance that is going to be started
78
     * @param   verbose Whether to show the informational dialog
79
     *
80
     * @return  required settings or <code>null</code> if user cancelled starting
81
     *          the server.
82
     */
83
    ProfilerServerSettings getDefaultServerSettings(String serverInstanceID, 
84
            boolean verbose);
85
    
86
    /**
87
     * Tests whether <code>session</code> could be configured for 
88
     * J2EE server start in profiling mode.
89
     * Provider should track started sessions.
90
     * Some providers could have limitations on such session 
91
     * (f.e. only one session at time). In the latter case this method
92
     * should return <code>false</code> if new session cannot be configured
93
     * for start ( J2EE server with this session cannot be started ).    
94
     * 
95
     * @param session new session which should be configured for new server start 
96
     * @return <code>true</code> if session can be configured and server can start
97
     */
98
    boolean canConfigure( ProfilerSession session );
99
}
(-)3358e7eefa36 (+155 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.j2ee.deployment.profiler.spi;
42
43
import javax.enterprise.deploy.spi.status.ProgressObject;
44
45
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerServerSettings;
46
import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerStateListener;
47
48
49
/**
50
 * @author sherold
51
 * @author ads
52
 *
53
 */
54
public interface ProfilerSession {
55
    
56
    /**
57
     * The Profiler agent isn't running.
58
     */
59
    public static final int STATE_INACTIVE  = 0;
60
61
    /**
62
     * The Profiler agent is starting to STATE_BLOCKING or STATE_RUNNING state,
63
     * target JVM isn't running.
64
     */
65
    public static final int STATE_STARTING  = 1;
66
    
67
    /**
68
     * The Profiler agent is running and ready for the Profiler to connect, target
69
     * JVM is blocked.
70
     */
71
    public static final int STATE_BLOCKING  = 2;
72
    
73
    /**
74
     * The Profiler agent is running and ready for the Profiler to connect, target
75
     * JVM is running.
76
     */
77
    public static final int STATE_RUNNING   = 3;
78
    
79
    /**
80
     * The Profiler agent is running and connected to Profiler, target JVM is running.
81
     */
82
    public static final int STATE_PROFILING = 4;
83
    
84
    /**
85
     * The Profiled agent is going to stop ( but it is not yet stopped ).
86
     * This state is used for notification server instance that server
87
     * should be cleaned up ( actually stopped via server specific API ). 
88
     */
89
    public static final int STATE_STOPPING  = 5;
90
    
91
92
   /**
93
    * Inform the profiler that some server is starting in the profile mode. It
94
    * allows the Profiler to correctly detect STATE_STARTING.
95
    */
96
   void notifyStarting();
97
   
98
   /**
99
    * This method is used from the <code>nbstartprofiledserver</code>
100
    * task to connect the Profiler to a server ready for profiling.
101
    *
102
    * @return <code>true</code> if the Profiler successfully attached to the server.
103
    */
104
   boolean attachProfiler();
105
   
106
   /**
107
    * Returns state of Profiler agent instance started from the IDE. It detects 
108
    * possible response from an unknown (not started from the IDE) Profiler
109
    * agent, in this case it returns STATE_INACTIVE.
110
    *
111
    * @return state of Profiler agent instance.
112
    */
113
   int getState();
114
   
115
   /**
116
    * Gets provider for this session.
117
    *  
118
    * @return provider  
119
    */
120
   ProfilerProvider getProvider();
121
   
122
   /**
123
    * Perform session configuration.
124
    * Session was produced by ProfilerProvider via ProfilerServerSettings.
125
    * This settings could be used by this method for session configuration.
126
    * Some of original start parameters in settings could be updated
127
    * or added for start new J2EE server instance with this session .    
128
    * 
129
    * @return settings which could differ from original settings used for session creation 
130
    */
131
   ProfilerServerSettings configureSession();
132
133
   /**
134
    * Inform the profiler that this session require stop.
135
    * This method should at least fire event about profiler state change.
136
    *
137
    * @return object used to monitor progress of shutdown.
138
    */
139
   ProgressObject notifyStop();
140
141
    /**
142
     * Adds profiler state listener to the session.
143
     * 
144
     * @param listener profiler state listener
145
     */
146
    void addProfilerStateListener( ProfilerStateListener listener );
147
148
    /**
149
     * Removes profiler state listener from the session.
150
     * 
151
     * @param listener profiler state listener
152
     */
153
    void removeProfilerStateListener( ProfilerStateListener listener );
154
155
}

Return to bug 182772