KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > plugin > DownloadResults


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.system.plugin;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import org.apache.geronimo.kernel.repository.Artifact;
23
24 /**
25  * Provides the results of a configuration download operation. This is updated
26  * along the way for callers who want to monitor the ongoing progress.
27  *
28  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
29  */

30 public class DownloadResults implements Serializable JavaDoc, DownloadPoller {
31     private List JavaDoc removedConfigIDs = new ArrayList JavaDoc();
32     private List JavaDoc restartedConfigIDs = new ArrayList JavaDoc();
33     private List JavaDoc installedConfigIDs = new ArrayList JavaDoc();
34     private List JavaDoc dependenciesPresent = new ArrayList JavaDoc();
35     private List JavaDoc dependenciesInstalled = new ArrayList JavaDoc();
36     private String JavaDoc currentFile;
37     private String JavaDoc currentMessage;
38     private int currentFileProgress = -1;
39     private Exception JavaDoc failure;
40     private boolean finished;
41     private long totalDownloadBytes = 0;
42
43     public synchronized DownloadResults duplicate() {
44         DownloadResults other = new DownloadResults();
45         other.removedConfigIDs.addAll(removedConfigIDs);
46         other.restartedConfigIDs.addAll(restartedConfigIDs);
47         other.installedConfigIDs.addAll(installedConfigIDs);
48         other.dependenciesPresent.addAll(dependenciesPresent);
49         other.dependenciesInstalled.addAll(dependenciesInstalled);
50         other.currentFile = currentFile;
51         other.currentMessage = currentMessage;
52         other.currentFileProgress = currentFileProgress;
53         other.failure = failure;
54         other.finished = finished;
55         other.totalDownloadBytes = totalDownloadBytes;
56         return other;
57     }
58
59     public synchronized void addInstalledConfigID(Artifact dep) {
60         installedConfigIDs.add(dep);
61     }
62
63     public synchronized void addRemovedConfigID(Artifact obsolete) {
64         removedConfigIDs.add(obsolete);
65     }
66
67     public synchronized void addRestartedConfigID(Artifact target) {
68         restartedConfigIDs.add(target);
69     }
70
71     public synchronized void addDependencyPresent(Artifact dep) {
72         dependenciesPresent.add(dep);
73     }
74
75     public synchronized void addDependencyInstalled(Artifact dep) {
76         dependenciesInstalled.add(dep);
77     }
78
79     public synchronized void setCurrentFile(String JavaDoc currentFile) {
80         this.currentFile = currentFile;
81     }
82
83     public synchronized void setCurrentMessage(String JavaDoc currentMessage) {
84         this.currentMessage = currentMessage;
85     }
86
87     public synchronized void setCurrentFilePercent(int currentFileProgress) {
88         this.currentFileProgress = currentFileProgress;
89     }
90
91     public synchronized void setFailure(Exception JavaDoc failure) {
92         this.failure = failure;
93     }
94
95     public synchronized void setFinished() {
96         finished = true;
97     }
98
99     public synchronized void addDownloadBytes(long bytes) {
100         totalDownloadBytes += bytes;
101     }
102
103     public boolean isFinished() {
104         return finished;
105     }
106
107     public boolean isFailed() {
108         return failure != null;
109     }
110
111     /**
112      * The total number of bytes in the archives downloaded from remote
113      * repositories.
114      */

115     public long getTotalDownloadBytes() {
116         return totalDownloadBytes;
117     }
118
119     /**
120      * If the operation failed, the Exception that caused the failure.
121      */

122     public Exception JavaDoc getFailure() {
123         return failure;
124     }
125
126     /**
127      * Gets the list of the originally requested Config IDs that were
128      * successfully installed. Ordinarily this is not necessary, but
129      * it may be important in case of failure midway through, or if the
130      * request passed previously downloaded configurations on the command
131      * line and the caller doesn't know what the Config IDs are.
132      */

133     public Artifact[] getInstalledConfigIDs() {
134         return (Artifact[]) installedConfigIDs.toArray(new Artifact[installedConfigIDs.size()]);
135     }
136
137     public Artifact[] getRemovedConfigIDs() {
138         return (Artifact[]) removedConfigIDs.toArray(new Artifact[installedConfigIDs.size()]);
139     }
140
141     public Artifact[] getRestartedConfigIDs() {
142         return (Artifact[]) restartedConfigIDs.toArray(new Artifact[installedConfigIDs.size()]);
143     }
144
145     /**
146      * Gets the dependencies that we've needed but they're already present in
147      * the local server so no installation was necessary.
148      */

149     public Artifact[] getDependenciesPresent() {
150         return (Artifact[]) dependenciesPresent.toArray(new Artifact[dependenciesPresent.size()]);
151     }
152
153     /**
154      * Gets the dependencies that we've successfully downloaded and installed
155      * into the local server environment.
156      */

157     public Artifact[] getDependenciesInstalled() {
158         return (Artifact[]) dependenciesInstalled.toArray(new Artifact[dependenciesInstalled.size()]);
159     }
160
161     /**
162      * Gets the name of the file that is currently being operated on.
163      */

164     public String JavaDoc getCurrentFile() {
165         return currentFile;
166     }
167
168     /**
169      * Gets a description of the work currently being done.
170      */

171     public String JavaDoc getCurrentMessage() {
172         return currentMessage;
173     }
174
175     /**
176      * Gets the progress on the current file expressed as a percentage. This
177      * value may be -1 in which case the progress cannot be calculated (e.g. a
178      * download where the server doesn't supply the file size up front).
179      */

180     public int getCurrentFilePercent() {
181         return currentFileProgress;
182     }
183 }
184
Popular Tags