1 /** 2 * 3 * Copyright 2005 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * 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; 20 import java.util.List; 21 import java.util.ArrayList; 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: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 2006) $ 29 */ 30 public class DownloadResults implements Serializable, DownloadPoller { 31 private List removedConfigIDs = new ArrayList(); 32 private List restartedConfigIDs = new ArrayList(); 33 private List installedConfigIDs = new ArrayList(); 34 private List dependenciesPresent = new ArrayList(); 35 private List dependenciesInstalled = new ArrayList(); 36 private String currentFile; 37 private String currentMessage; 38 private int currentFileProgress = -1; 39 private Exception 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 currentFile) { 80 this.currentFile = currentFile; 81 } 82 83 public synchronized void setCurrentMessage(String 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 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 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 getCurrentFile() { 165 return currentFile; 166 } 167 168 /** 169 * Gets a description of the work currently being done. 170 */ 171 public String 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 }