Changeset 31670
- Timestamp:
- 2017-05-10T18:31:55+12:00 (7 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r31644 r31670 1676 1676 } 1677 1677 DebugStream.println("***** Running ImageMagickTest command: " + cmd_str); 1678 System.err.println("***** Running ImageMagickTest command: " + cmd_str);1679 1678 1680 1679 SafeProcess image_magick_process = new SafeProcess(command_parts); … … 1684 1683 String output = image_magick_process.getStdOutput().toLowerCase(); 1685 1684 if (output.indexOf("version") != -1 || output.indexOf("imagemagick") != -1) { 1686 System.err.println("*** ImageMagickTest output: " + output);1687 1685 found = true; 1688 1686 } // else found var remains false -
main/trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
r31666 r31670 41 41 import java.util.ArrayList; 42 42 import java.util.Enumeration; 43 import java.util.concurrent.CopyOnWriteArrayList; 43 44 import java.util.regex.*; 44 45 import javax.swing.*; … … 68 69 private boolean cancel = false; 69 70 private BufferedOutputStream buffered_output_stream = null; 70 /** The list of listeners associated with this class. */ 71 private EventListenerList listeners = null; 71 /** The list of listeners associated with this class. 72 * Make it a CopyOnWriteArrayList to make it threadsafe at a cost of decreased efficiency. 73 * see http://stackoverflow.com/questions/8259479/should-i-synchronize-listener-notifications-or-not 74 */ 75 private final CopyOnWriteArrayList<GShellListener> listeners; 72 76 /** The current status of this shell process. */ 73 77 private int status = -1; … … 85 89 private String commandOutput = null; 86 90 87 /** The process safely run in this GShell . Make sure to setto null when done with. */88 SafeProcess prcs = null;91 /** The process safely run in this GShell Thread. Make sure to set to prcs to null when done with. */ 92 private SafeProcess prcs = null; 89 93 90 94 /** Elements in process type enumeration. */ … … 136 140 // Lower this jobs priority 137 141 this.setPriority(Thread.MIN_PRIORITY); 138 listeners = new EventListenerList();139 listeners.add( GShellListener.class,caller);142 listeners = new CopyOnWriteArrayList<GShellListener>(); 143 listeners.add(caller); 140 144 } 141 145 /** This method adds another shell listener to this process. … … 143 147 */ 144 148 public void addGShellListener(GShellListener listener) { 145 listeners.add( GShellListener.class,listener);149 listeners.add(listener); 146 150 } 147 151 /** This method removes a certain shell listener from this process. … … 149 153 */ 150 154 /* private void removeGShellListener(GShellListener listener) { 151 listeners.remove( GShellListener.class,listener);155 listeners.remove(listener); 152 156 } */ 153 157 … … 549 553 // If the event hasn't been vetoed, pass it on to other listeners 550 554 if(!current_event.isVetoed()) { 551 Object[] concerned = listeners.getListenerList(); 552 for(int i = 0; i < concerned.length ; i++) { 553 if(concerned[i] == GShellListener.class) { 554 ((GShellListener)concerned[i+1]).message(current_event); 555 } 556 } 557 concerned = null; 555 // See http://stackoverflow.com/questions/8259479/should-i-synchronize-listener-notifications-or-not 556 for (GShellListener l: this.listeners) { 557 l.message(current_event); 558 } 558 559 } 559 560 } … … 585 586 // Fire an event 586 587 GShellEvent event = new GShellEvent(this, 0, type, "", status); 587 Object[] concerned = listeners.getListenerList(); 588 for(int i = 0; i < concerned.length ; i++) { 589 if(concerned[i] == GShellListener.class) { 590 ((GShellListener)concerned[i+1]).processBegun(event); 591 } 588 for (GShellListener l: this.listeners) { 589 l.processBegun(event); 592 590 } 593 591 } … … 607 605 if(status == CANCELLED && Configuration.getMode() <= Configuration.LIBRARIAN_MODE) { 608 606 GShellEvent current_event = new GShellEvent(this, 0, type, Dictionary.get("GShell.Build.BuildCancelled"), status); 609 Object[] concerned = listeners.getListenerList(); 610 for(int i = 0; i < concerned.length ; i++) { 611 if(concerned[i] == GShellListener.class) { 612 ((GShellListener)concerned[i+1]).message(current_event); 613 } 614 } 615 concerned = null; 607 for (GShellListener l: this.listeners) { 608 l.message(current_event); 609 } 616 610 } 617 611 … … 623 617 // And firing off an event 624 618 GShellEvent event = new GShellEvent(this, 0, type, msg, status); 625 Object[] concerned = listeners.getListenerList(); 626 for(int i = 0; i < concerned.length ; i++) { 627 if(concerned[i] == GShellListener.class) { 628 ((GShellListener)concerned[i+1]).processComplete(event); 629 } 619 for (GShellListener l: this.listeners) { 620 l.processComplete(event); 630 621 } 631 622 }
Note:
See TracChangeset
for help on using the changeset viewer.