1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | *
|
---|
4 | * A component of the Greenstone Librarian Interface application, part of
|
---|
5 | * the Greenstone digital library suite from the New Zealand Digital
|
---|
6 | * Library Project at the University of Waikato, New Zealand.
|
---|
7 | *
|
---|
8 | * Author: Michael Dewsnip, NZDL Project, University of Waikato
|
---|
9 | *
|
---|
10 | * Copyright (C) 2005 New Zealand Digital Library Project
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or modify
|
---|
13 | * it under the terms of the GNU General Public License as published by
|
---|
14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
15 | * (at your option) any later version.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful,
|
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | * GNU General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, write to the Free Software
|
---|
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | *########################################################################
|
---|
26 | */
|
---|
27 |
|
---|
28 | package org.greenstone.gatherer.remote;
|
---|
29 |
|
---|
30 | import java.io.*;
|
---|
31 | import java.net.*;
|
---|
32 | import java.util.*;
|
---|
33 | import java.util.zip.*;
|
---|
34 | import javax.swing.*;
|
---|
35 | import java.io.ByteArrayOutputStream;
|
---|
36 | import org.greenstone.gatherer.Configuration;
|
---|
37 | import org.greenstone.gatherer.DebugStream;
|
---|
38 | import org.greenstone.gatherer.Dictionary;
|
---|
39 | import org.greenstone.gatherer.FedoraInfo;
|
---|
40 | import org.greenstone.gatherer.GAuthenticator;
|
---|
41 | import org.greenstone.gatherer.Gatherer;
|
---|
42 | import org.greenstone.gatherer.collection.CollectionManager;
|
---|
43 | import org.greenstone.gatherer.shell.GShell;
|
---|
44 | import org.greenstone.gatherer.util.UnzipTools;
|
---|
45 | import org.greenstone.gatherer.util.Utility;
|
---|
46 | import org.apache.commons.httpclient.HttpClient;
|
---|
47 | import org.apache.commons.httpclient.methods.PostMethod;
|
---|
48 | import org.apache.commons.httpclient.methods.GetMethod;
|
---|
49 | import org.apache.commons.httpclient.HttpException;
|
---|
50 | import org.apache.commons.httpclient.methods.multipart.FilePart;
|
---|
51 | import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
---|
52 | import org.apache.commons.httpclient.methods.multipart.Part;
|
---|
53 | import org.apache.commons.httpclient.methods.multipart.*;
|
---|
54 | import org.apache.commons.httpclient.params.*;
|
---|
55 | import org.apache.commons.httpclient.HttpStatus;
|
---|
56 |
|
---|
57 | // ----------------------------------------------------------------------------------------------------
|
---|
58 | // Part of the RemoteGreenstoneServer's QUEUE LAYER
|
---|
59 | // ----------------------------------------------------------------------------------------------------
|
---|
60 |
|
---|
61 | // Moved here. Previously called RemoteGreenstoneServerActionQueue
|
---|
62 | /**
|
---|
63 | * A Thread that maintains a queue of RemoteGreenstoneServer Actions
|
---|
64 | * that are to be executed in FIFO fashion.
|
---|
65 | */
|
---|
66 | class ActionQueue extends Thread
|
---|
67 | {
|
---|
68 | /** The queue of waiting jobs. */
|
---|
69 | private ArrayList queue = null;
|
---|
70 |
|
---|
71 |
|
---|
72 | public ActionQueue()
|
---|
73 | {
|
---|
74 | if (Gatherer.isGsdlRemote) {
|
---|
75 | queue = new ArrayList();
|
---|
76 | start();
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | synchronized public void addAction(RemoteGreenstoneServerAction remote_greenstone_server_action)
|
---|
82 | {
|
---|
83 | queue.add(remote_greenstone_server_action);
|
---|
84 | notifyAll();
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | public int size()
|
---|
89 | {
|
---|
90 | return queue.size();
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | public void run()
|
---|
95 | {
|
---|
96 | boolean exit = false;
|
---|
97 | while (!exit) {
|
---|
98 | // If there are jobs on the queue, get the next in line and process it
|
---|
99 | if (queue.size() > 0) {
|
---|
100 | RemoteGreenstoneServerAction remote_greenstone_server_action = (RemoteGreenstoneServerAction) queue.get(0);
|
---|
101 |
|
---|
102 | try {
|
---|
103 | remote_greenstone_server_action.perform();
|
---|
104 |
|
---|
105 | // No exceptions were thrown, so the action was successful
|
---|
106 | remote_greenstone_server_action.processed_successfully = true;
|
---|
107 | }
|
---|
108 | catch (RemoteGreenstoneServerAction.ActionCancelledException exception) {
|
---|
109 | remote_greenstone_server_action.processed_successfully = false;
|
---|
110 | exit = true;
|
---|
111 | }
|
---|
112 | catch(java.net.ConnectException exception) {
|
---|
113 | if(exception.getMessage().trim().startsWith("Connection refused")) {
|
---|
114 | exit = true;
|
---|
115 | } else {
|
---|
116 | DebugStream.printStackTrace(exception);
|
---|
117 | }
|
---|
118 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("RemoteGreenstoneServer.Error", exception.getMessage()), Dictionary.get("RemoteGreenstoneServer.Error_Title"), JOptionPane.ERROR_MESSAGE);
|
---|
119 | remote_greenstone_server_action.processed_successfully = false;
|
---|
120 | }
|
---|
121 | catch (FileNotFoundException exception) {
|
---|
122 | // FileNotFoundException happens when there's no GS server at the user-provided
|
---|
123 | // url (the address of gliserver.pl is wrong).
|
---|
124 | exit = true;
|
---|
125 | DebugStream.printStackTrace(exception);
|
---|
126 | JOptionPane.showMessageDialog(Gatherer.g_man,
|
---|
127 | Dictionary.get("RemoteGreenstoneServer.Error",
|
---|
128 | "No gliserver.pl found. " + exception.getMessage()),
|
---|
129 | Dictionary.get("RemoteGreenstoneServer.Error_Title"),
|
---|
130 | JOptionPane.ERROR_MESSAGE);
|
---|
131 | remote_greenstone_server_action.processed_successfully = false;
|
---|
132 | }
|
---|
133 | catch (Exception exception) {
|
---|
134 | DebugStream.printStackTrace(exception);
|
---|
135 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("RemoteGreenstoneServer.Error", exception.getMessage()), Dictionary.get("RemoteGreenstoneServer.Error_Title"), JOptionPane.ERROR_MESSAGE);
|
---|
136 | remote_greenstone_server_action.processed_successfully = false;
|
---|
137 | }
|
---|
138 |
|
---|
139 | // We're done with this action, for better or worse
|
---|
140 | remote_greenstone_server_action.processed = true;
|
---|
141 | queue.remove(0);
|
---|
142 | }
|
---|
143 |
|
---|
144 | // Otherwise the queue is empty
|
---|
145 | else {
|
---|
146 | Gatherer.remoteGreenstoneServer.getProgressBar().setAction(null);
|
---|
147 |
|
---|
148 | // Wait until we are notify()ed by addAction that there is a new job on the queue
|
---|
149 | synchronized (this) {
|
---|
150 | try {
|
---|
151 | wait();
|
---|
152 | }
|
---|
153 | catch (InterruptedException exception) { }
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | }
|
---|
158 | // stop the gazillion annoying error messages when the connection was simply
|
---|
159 | // refused or when the user pressed Cancel in the opening dialog, by exitting
|
---|
160 | // cleanly in one go.
|
---|
161 | //if(exit == true) {
|
---|
162 | //Gatherer.exit();
|
---|
163 | //}
|
---|
164 | }
|
---|
165 | } |
---|