001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.deploy;
031:
032: import com.caucho.log.Log;
033: import com.caucho.util.L10N;
034: import com.caucho.vfs.Dependency;
035:
036: import java.util.ArrayList;
037: import java.util.Set;
038: import java.util.logging.Level;
039: import java.util.logging.Logger;
040:
041: /**
042: * A list of deploy objects.
043: */
044: public class DeployListGenerator<E extends DeployController> extends
045: DeployGenerator<E> implements Dependency {
046: private static final Logger log = Log
047: .open(DeployListGenerator.class);
048: private static final L10N L = new L10N(DeployListGenerator.class);
049:
050: private ArrayList<DeployGenerator<E>> _generatorList = new ArrayList<DeployGenerator<E>>();
051:
052: /**
053: * Creates the deploy.
054: */
055: public DeployListGenerator(DeployContainer container) {
056: super (container);
057: }
058:
059: /**
060: * Adds a deploy.
061: */
062: public void add(DeployGenerator<E> deploy) {
063: if (!_generatorList.contains(deploy))
064: _generatorList.add(deploy);
065: }
066:
067: /**
068: * Removes a deploy.
069: */
070: public void remove(DeployGenerator<E> deploy) {
071: _generatorList.remove(deploy);
072: }
073:
074: /**
075: * Returns true if the deployment has modified.
076: */
077: public boolean isModified() {
078: for (int i = _generatorList.size() - 1; i >= 0; i--) {
079: if (_generatorList.get(i).isModified())
080: return true;
081: }
082:
083: return false;
084: }
085:
086: /**
087: * Logs the modified location.
088: */
089: public boolean logModified(Logger log) {
090: for (int i = _generatorList.size() - 1; i >= 0; i--) {
091: if (_generatorList.get(i).logModified(log))
092: return true;
093: }
094:
095: return false;
096: }
097:
098: /**
099: * Redeploy if the deployment is modified.
100: *
101: * XXX:
102: */
103: public void request() {
104: for (int i = _generatorList.size() - 1; i >= 0; i--) {
105: _generatorList.get(i).request();
106: }
107: }
108:
109: /**
110: * Force an update
111: */
112: public void update() {
113: for (int i = 0; i < _generatorList.size(); i++)
114: _generatorList.get(i).update();
115: }
116:
117: /**
118: * Returns the deployed keys.
119: */
120: public void fillDeployedKeys(Set<String> keys) {
121: for (int i = 0; i < _generatorList.size(); i++) {
122: _generatorList.get(i).fillDeployedKeys(keys);
123: }
124: }
125:
126: /**
127: * Generates the controller matching the key string.
128: */
129: protected E generateController(String key) {
130: for (int i = 0; i < _generatorList.size(); i++) {
131: E controller = _generatorList.get(i)
132: .generateController(key);
133:
134: // merge with the rest of the entries
135: for (int j = 0; controller != null
136: && j < _generatorList.size(); j++) {
137: DeployGenerator<E> generator = _generatorList.get(j);
138:
139: // XXX: issue with server/10tl
140: controller = _generatorList.get(j).mergeController(
141: controller, key);
142: }
143:
144: if (controller != null)
145: return controller;
146: }
147:
148: return null;
149: }
150:
151: /**
152: * Merges with other matching entries.
153: */
154: protected E mergeController(E controller, String key) {
155: for (int i = 0; i < _generatorList.size(); i++) {
156: controller = _generatorList.get(i).mergeController(
157: controller, key);
158: }
159:
160: return controller;
161: }
162:
163: /**
164: * Starts the deploys.
165: */
166: @Override
167: protected void startImpl() {
168: super .startImpl();
169:
170: for (int i = 0; i < _generatorList.size(); i++) {
171: _generatorList.get(i).start();
172: }
173: }
174:
175: /**
176: * Stops the deploys.
177: */
178: @Override
179: protected void stopImpl() {
180: for (int i = 0; i < _generatorList.size(); i++) {
181: _generatorList.get(i).stop();
182: }
183:
184: super .stopImpl();
185: }
186:
187: /**
188: * Closes the deploys.
189: */
190: @Override
191: protected void destroyImpl() {
192: ArrayList<DeployGenerator<E>> generatorList = new ArrayList<DeployGenerator<E>>(
193: _generatorList);
194:
195: _generatorList.clear();
196:
197: for (int i = 0; i < generatorList.size(); i++) {
198: try {
199: generatorList.get(i).destroy();
200: } catch (Throwable e) {
201: log.log(Level.FINE, e.toString(), e);
202: }
203: }
204:
205: super .destroyImpl();
206: }
207:
208: public String toString() {
209: return "DeployListGenerator[" + _generatorList + "]";
210: }
211: }
|