source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build/CollectionConstructor.java@ 31771

Last change on this file since 31771 was 31771, checked in by kjdon, 7 years ago

we need to pass library_name to the incremental-buildcol so that it can deactivate the collection before modifying the database

  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1package org.greenstone.gsdl3.build;
2
3import java.io.File;
4
5import org.greenstone.gsdl3.util.*;
6//import java.util.Thread
7import java.util.concurrent.CopyOnWriteArrayList;
8import org.w3c.dom.Element;
9
10/** base class for collection construction */
11public abstract class CollectionConstructor extends Thread
12{
13
14 /** the site in which building is to take place */
15 protected String site_home = null;
16 /** the name of the site */
17 protected String site_name = null;
18 /** the library (servlet) name of the site */
19 protected String library_name = null;
20 /** the name of the collection */
21 protected String collection_name = null;
22 /** the stage of construction */
23 protected int process_type = -1;
24 /** other arguments/parameters for the construction process - in a paramList */
25 protected Element process_params = null;
26 /** the list of listeners for the process. We need it to be threadsafe.
27 * see http://stackoverflow.com/questions/8259479/should-i-synchronize-listener-notifications-or-not
28 * https://docs.oracle.com/javase/6/docs/api/java/util/concurrent/CopyOnWriteArrayList.html
29 * "A thread-safe variant of ArrayList in which all mutative operations (add, set, and so on) are
30 * implemented by making a fresh copy of the underlying array.
31 * This is ordinarily too costly, but may be more efficient than alternatives when traversal operations
32 * vastly outnumber mutations, and is useful when you cannot or don't want to synchronize traversals,
33 * yet need to preclude interference among concurrent threads."
34 */
35 protected final CopyOnWriteArrayList<ConstructionListener> listeners;
36 /** A flag used to determine if this process has been asked to cancel. */
37 protected boolean cancel = false; // Not really used (in any way that works)
38 /** Stores the name of the manifest file (if one is needed) */
39 protected String manifest_file = null;
40 /** The URL params constructed as a query string, representing the CGI QUERY_STRING to the process */
41 protected String query_string = null;
42
43 public CollectionConstructor(String name)
44 {
45 super(name);
46 this.listeners = new CopyOnWriteArrayList<ConstructionListener>();
47 }
48
49 /**
50 * carry out any set up stuff - returns false if couldn't set up properly
51 */
52 public boolean configure()
53 {
54 return true;
55 }
56
57 // this method never gets called. And, the way subclass GS2PerlConstructor.runPerlCommand() was originally
58 // coded, setting cancel to true never had any effect anyway in stopping any perl command that was run.
59 public void stopAction()
60 {
61 this.cancel = true;
62 }
63
64 public void setActionType(int type)
65 {
66 this.process_type = type;
67 }
68
69 public void setSiteHome(String site_home)
70 {
71 this.site_home = site_home;
72
73 File siteHomeFile = new File(site_home);
74 this.site_name = siteHomeFile.getName();
75 }
76
77 public void setLibraryName(String library_name) {
78 this.library_name = library_name;
79 }
80 public void setCollectionName(String coll_name)
81 {
82 this.collection_name = coll_name;
83 }
84
85 public void setQueryString(String querystring)
86 {
87 this.query_string = querystring;
88 }
89
90 public void setProcessParams(Element params)
91 {
92 this.process_params = params;
93 }
94
95 public void setManifestFile(String manifestFile)
96 {
97 this.manifest_file = manifestFile;
98 }
99
100 public boolean addListener(ConstructionListener listener)
101 {
102 this.listeners.add(listener);
103 return true;
104 }
105
106 // We never call removeListener. If we do start calling removeListener() change the listeners list
107 // over to type ConcurrentLinkedQueue, for reasons explained at
108 // http://stackoverflow.com/questions/8259479/should-i-synchronize-listener-notifications-or-not
109 // The current listeners list type is CopyOnWriteArrayList, which provides thread safety. But it
110 // can still send off events to listeners just as they're being unregistered, and that could be a
111 // problem if we were specifically removing the listener because we wanted to cease it from
112 // listening and responding to subsequent events.
113 public boolean removeListener(ConstructionListener listener)
114 {
115 this.listeners.remove(listener);
116 return true;
117 }
118
119 protected void sendProcessBegun(ConstructionEvent evt)
120 {
121 // See http://stackoverflow.com/questions/8259479/should-i-synchronize-listener-notifications-or-not
122 for (ConstructionListener l: this.listeners) {
123 l.processBegun(evt);
124 }
125 }
126
127 protected void sendProcessComplete(ConstructionEvent evt)
128 {
129 for (ConstructionListener l: this.listeners) {
130 l.processComplete(evt);
131 }
132 }
133
134 // Method doesn't need to be synchronized any more, since it uses the ThreadSafe CopyOnWriteArrayList
135 // for listeners list.
136 // See http://stackoverflow.com/questions/8259479/should-i-synchronize-listener-notifications-or-not
137 // See http://stackoverflow.com/questions/574240/is-there-an-advantage-to-use-a-synchronized-method-instead-of-a-synchronized-blo
138 protected void sendProcessStatus(ConstructionEvent evt)
139 {
140 for (ConstructionListener l: this.listeners) {
141 l.processStatus(evt);
142 }
143 }
144
145 protected void sendMessage(ConstructionEvent evt)
146 {
147 for (ConstructionListener l: this.listeners) {
148 l.message(evt);
149 }
150 }
151
152 abstract public void run();
153}
Note: See TracBrowser for help on using the repository browser.