Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 204942 - PTP console window output
Summary: PTP console window output
Status: RESOLVED FIXED
Alias: None
Product: PTP
Classification: Tools
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Feiyi Wang CLA
QA Contact: Greg Watson CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-28 14:42 EDT by Feiyi Wang CLA
Modified: 2011-01-31 07:49 EST (History)
1 user (show)

See Also:
fwang2: review?


Attachments
new console class (3.56 KB, text/x-java)
2007-09-28 14:44 EDT, Feiyi Wang CLA
no flags Details
attach console to each new job (1.26 KB, patch)
2007-09-28 14:48 EDT, Feiyi Wang CLA
no flags Details | Diff
console manager (3.92 KB, text/x-java)
2007-10-15 12:22 EDT, Feiyi Wang CLA
no flags Details
console class that handle process output (4.48 KB, text/x-java)
2007-10-15 12:23 EDT, Feiyi Wang CLA
no flags Details
patch to initialize ConsoleManger at the startup. (1.79 KB, patch)
2007-10-15 12:27 EDT, Feiyi Wang CLA
g.watson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Feiyi Wang CLA 2007-09-28 14:42:51 EDT
this feature will allow stdout from executing process to be displayed on console window - on a per job basis, as you would normally expect when printf() is called. This is a 2.0 TODO item as I understand. It is complementary to what we have now (click on each process to view its output) in the sense that it combines and displays console output on the fly as processes run. 

My initial implementation will be provided later once the format requirement is clear.
Comment 1 Feiyi Wang CLA 2007-09-28 14:44:14 EDT
Created attachment 79416 [details]
new console class
Comment 2 Feiyi Wang CLA 2007-09-28 14:48:46 EDT
Created attachment 79417 [details]
attach console to each new job
Comment 3 Greg Watson CLA 2007-10-05 13:19:12 EDT
Feiyi,

I've taken a look at this and there are a few things that need to be fixed up before it can be committed.

1. Each source file has to have the default Eclipse copyright and license notice. This is something like:

/*******************************************************************************
 * Copyright (c) 2007 <your company> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * <your company> - Initial API and implementation
 *******************************************************************************/

2. Contributions of UI functionality should be in org.eclipse.ptp.ui rather than org.eclipse.ptp.core. There should be no UI dependencies in org.eclipse.ptp.core. I suggest putting PConsole in org.eclipse.ptp.ui.consoles.

3. Comment (2) also applies to the patch to AbstractResourceManager. This should all be done in the UI plugin. Also, you'll need to remove consoles when jobs a removed. I think the way to do this is to add the new console to the console view using the console manager. You do this using ConsolePlugin.getConsoleManager().addConsoles() when the job starts and removeConsoles() when the job terminates (I've never done this so you'll need to check it works) See org.eclipse.ui.console for more information.

4. You can register for new/remove job events by adding a child listener to all queues. Note that you'll also need to listen for new/removed queues so you can update the child listeners. This should be done in the PTPUIPlugin.start() method. See the way JobManager and MachineManager do it. I'd suggest creating a ConsoleManager.

5. You'll now need to listen for element events on each process of job to get the attributes. You can set this up when you get a new job event.

6. I'd also suggest naming the PConsole class something like JobConsole. I'm trying to get away from this P stuff.

Thanks!
Comment 4 Greg Watson CLA 2007-10-05 13:22:53 EDT
(In reply to comment #3)

> 3. Comment (2) also applies to the patch to AbstractResourceManager. This
> should all be done in the UI plugin. Also, you'll need to remove consoles when
> jobs a removed. I think the way to do this is to add the new console to the
> console view using the console manager. You do this using
> ConsolePlugin.getConsoleManager().addConsoles() when the job starts and
> removeConsoles() when the job terminates (I've never done this so you'll need
> to check it works) See org.eclipse.ui.console for more information.

Now I think about it, you should probably remove the console when the job is removed, not when it terminates.

Greg
Comment 5 Feiyi Wang CLA 2007-10-11 14:09:36 EDT
Greg -

Comment 1, 2,3,5,6 are clear. I will make changes correspondingly. Regarding #4, to create a ConsoleManager when plugin starts. I have one question though: suppose I have ConsoleManager to implements the QueueChildListener interface, what would be appropriate place to register self and to who. There is a protected modelPresentation variable in AbstractUIMananger, but I am not sure if  and how to get to model element such as Queue to add to their listener list.

Thanks

Feiyi





(In reply to comment #3)
> Feiyi,
> 
> I've taken a look at this and there are a few things that need to be fixed up
> before it can be committed.
> 
> 1. Each source file has to have the default Eclipse copyright and license
> notice. This is something like:
> 
> /*******************************************************************************
>  * Copyright (c) 2007 <your company> and others.
>  * All rights reserved. This program and the accompanying materials
>  * are made available under the terms of the Eclipse Public License v1.0
>  * which accompanies this distribution, and is available at
>  * http://www.eclipse.org/legal/epl-v10.html
>  *
>  * Contributors:
>  * <your company> - Initial API and implementation
> 
> *******************************************************************************/
> 
> 2. Contributions of UI functionality should be in org.eclipse.ptp.ui rather
> than org.eclipse.ptp.core. There should be no UI dependencies in
> org.eclipse.ptp.core. I suggest putting PConsole in
> org.eclipse.ptp.ui.consoles.
> 
> 3. Comment (2) also applies to the patch to AbstractResourceManager. This
> should all be done in the UI plugin. Also, you'll need to remove consoles when
> jobs a removed. I think the way to do this is to add the new console to the
> console view using the console manager. You do this using
> ConsolePlugin.getConsoleManager().addConsoles() when the job starts and
> removeConsoles() when the job terminates (I've never done this so you'll need
> to check it works) See org.eclipse.ui.console for more information.
> 
> 4. You can register for new/remove job events by adding a child listener to all
> queues. Note that you'll also need to listen for new/removed queues so you can
> update the child listeners. This should be done in the PTPUIPlugin.start()
> method. See the way JobManager and MachineManager do it. I'd suggest creating a
> ConsoleManager.
> 
> 5. You'll now need to listen for element events on each process of job to get
> the attributes. You can set this up when you get a new job event.
> 
> 6. I'd also suggest naming the PConsole class something like JobConsole. I'm
> trying to get away from this P stuff.
> 
> Thanks!
> 

Comment 6 Greg Watson CLA 2007-10-11 17:49:19 EDT
Looking at JobManager, etc., I'd suggest not extending AbstractUIManager. It does a whole lot of stuff you're not interested in. I'd start with a brand new ConsoleManager class that does something like the following. Create an instance of the class in the PTPUIPlugin.start() method.

1. Get the model manager using PTPCorePlugin.getDefault().getModelManager().

2. Register an IModelManagerChildListener, for each resource manager register an IResourceManagerChildListener, and for each queue register an IQueueChildListener.

3. In the handlers for INewResourceManagerEvent and IRemoveResourceManagerEvent, you should add and remove IResourceManagerChildListeners respectively.

4. In the handlers for INewQueueEvent and IRemoveQueueEvent, you should add and remove IQueueChildListeners respectively.

5. When you receive an INewJobEvent, you should create a new IOConsole and IOConsoleOutputStream and register it with ConsolePlugin.getConsoleManager().addConsoles(). You'll also need to keep the IOConsoleOutputStream associated with the job in some data structure. You'll also need to add an IJobChildListener.

6. When you receive an IRemoveJobEvent, you should remove the console using ConsolePlugin.getConsoleManager().removeConsoles(), and remove the IJobChildListener.

7. In the handlers for INewProcessEvent and IRemoveProcessEvent, you should add and remove IProcessLiseners for each process.

8. In the handler for IProcessChangeEvent you can obtain the standard out attribute, look up the IOConsoleOutputStream associated with this processes job, send the output to the console using IOConsoleOutputStream.write().

Greg

Comment 7 Feiyi Wang CLA 2007-10-12 16:24:20 EDT
> 
> 3. In the handlers for INewResourceManagerEvent and
> IRemoveResourceManagerEvent, you should add and remove
> IResourceManagerChildListeners respectively.

hmm ... I don't see IResourceManagerChildListener define handlers for IRemoveResoruceManagerEvent or INewResourceManagerEvent. IResourceManagerListener has handler for IResourceManagerChangeEvent, but it is suppose for attributes changes. Supposely, there could be IUniversityChildListener, but it is not defined. Did I misunderstand something here?


Feiyi
Comment 8 Greg Watson CLA 2007-10-12 16:37:09 EDT
Handlers for IRemoveResoruceManagerEvent and INewResourceManagerEvent are defined in IModelManagerChildListener. The INew* and IRemove* handlers are always in the child listener of the parent element (model manager is the parent of resource manager).
Comment 9 Feiyi Wang CLA 2007-10-12 17:48:39 EDT
Yes, I misread the statement ... 

I have it implemented and tested, seems working. Before I upload, one question, MessageConsole is created with a name (String type). For now, I use job.getId() as it is unique, but it is different from the name displayed in UI (job.getName() gives you a Job02). Is there better way of naming the console?

Thanks

Feiyi 


(In reply to comment #8)
> Handlers for IRemoveResoruceManagerEvent and INewResourceManagerEvent are
> defined in IModelManagerChildListener. The INew* and IRemove* handlers are
> always in the child listener of the parent element (model manager is the parent
> of resource manager).
> 

Comment 10 Greg Watson CLA 2007-10-12 20:05:02 EDT
If you want a unique name, you should concatenate the name of the resource manager, the queue and the job. e.g. 

String name = rm.getName() + ":" + queue.getName() + ":" + job.getName()

You could just use job.getName(), but there's a chance that jobs from different queues might have the same name.
Comment 11 Feiyi Wang CLA 2007-10-15 12:22:49 EDT
Created attachment 80365 [details]
console manager
Comment 12 Feiyi Wang CLA 2007-10-15 12:23:40 EDT
Created attachment 80366 [details]
console class that handle process output
Comment 13 Feiyi Wang CLA 2007-10-15 12:27:56 EDT
Created attachment 80368 [details]
patch to initialize ConsoleManger at the startup.
Comment 14 Greg Watson CLA 2007-10-19 11:36:06 EDT
I have committed this with the following changes:

ConsoleManager:

- The console manager maintains a mapping between jobs and JobConsoles
- Removed handlers and JobConsole when a job is removed ("remove terminated jobs" action)
- Added a shutdown() method that removes all handlers and JobConsoles
- Added flag to enable/disable job consoles (default disable)

JobConsole:

- Added flag to prefix output by process index (default enable)
- Moved getUniqueName() from ConsoleManager to JobConsole
- Only call getNewStream() once, when the console is first created

There are few things that still need to be done:

1. Add preference setting to enable/disable job consoles
2. Add preference setting to enable/disable output prefixing
3. Ensure all methods have javadoc comments
4. Remove and/or fix the jout() method which still calls newMessageStream() 
5. getUniqueName() can contain symbols (e.g. @) which don't seem to be displayed properly on the console tab. Need to work out what is happening here.

Some general pointers on coding:

- All new code needs to have javadoc and non-javadoc comments on every method.
- Please keep methods sorted (Source>Sort Members...) and formatted (Source>Format)

Thanks!
Comment 15 Greg Watson CLA 2008-02-19 12:09:24 EST
Added check box to enable console when job is launched. Output prefixing is always enabled. This is enough for 2.0 release.