You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/01/04 21:57:09 UTC
svn commit: r492735 - in
/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi:
container/ event/ framework/
Author: gnodet
Date: Thu Jan 4 12:57:08 2007
New Revision: 492735
URL: http://svn.apache.org/viewvc?view=rev&rev=492735
Log:
SM-803: Deployment events for a more pluggable hot deployer
Added:
incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentAdapter.java (with props)
incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentEvent.java (with props)
incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentListener.java (with props)
Modified:
incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java?view=diff&rev=492735&r1=492734&r2=492735
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java Thu Jan 4 12:57:08 2007
@@ -56,6 +56,7 @@
import org.apache.servicemix.id.IdGenerator;
import org.apache.servicemix.jbi.event.ComponentListener;
import org.apache.servicemix.jbi.event.ContainerAware;
+import org.apache.servicemix.jbi.event.DeploymentListener;
import org.apache.servicemix.jbi.event.EndpointListener;
import org.apache.servicemix.jbi.event.ExchangeEvent;
import org.apache.servicemix.jbi.event.ExchangeListener;
@@ -438,6 +439,20 @@
}
/**
+ * @return the deploymentExtensions
+ */
+ public String getDeploymentExtensions() {
+ return autoDeployService.getExtensions();
+ }
+
+ /**
+ * @param deploymentExtensions the deploymentExtensions to set
+ */
+ public void setDeploymentExtensions(String deploymentExtensions) {
+ autoDeployService.setExtensions(deploymentExtensions);
+ }
+
+ /**
* Install an component from a url
*
* @param url
@@ -1208,6 +1223,7 @@
}
public void addListener(EventListener listener) {
+ log.debug("Adding listener: " + listener.getClass());
if (listener instanceof ContainerAware) {
ContainerAware containerAware = (ContainerAware) listener;
containerAware.setContainer(this);
@@ -1227,9 +1243,13 @@
if (listener instanceof EndpointListener) {
listeners.add(EndpointListener.class, (EndpointListener) listener);
}
+ if (listener instanceof DeploymentListener) {
+ listeners.add(DeploymentListener.class, (DeploymentListener) listener);
+ }
}
public void removeListener(EventListener listener) {
+ log.debug("Removing listener: " + listener.getClass());
if (listener instanceof ExchangeListener) {
listeners.remove(ExchangeListener.class, (ExchangeListener) listener);
}
@@ -1244,6 +1264,9 @@
}
if (listener instanceof EndpointListener) {
listeners.remove(EndpointListener.class, (EndpointListener) listener);
+ }
+ if (listener instanceof DeploymentListener) {
+ listeners.remove(DeploymentListener.class, (DeploymentListener) listener);
}
}
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentAdapter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentAdapter.java?view=auto&rev=492735
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentAdapter.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentAdapter.java Thu Jan 4 12:57:08 2007
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.event;
+
+import java.io.IOException;
+
+public class DeploymentAdapter implements DeploymentListener {
+
+ public boolean fileAdded(DeploymentEvent event) throws IOException {
+ return false;
+ }
+
+ public boolean fileChanged(DeploymentEvent event) throws IOException {
+ return false;
+ }
+
+ public boolean fileRemoved(DeploymentEvent event) throws IOException {
+ return false;
+ }
+
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentAdapter.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentAdapter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentEvent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentEvent.java?view=auto&rev=492735
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentEvent.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentEvent.java Thu Jan 4 12:57:08 2007
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.event;
+
+import java.io.File;
+import java.util.EventObject;
+
+public class DeploymentEvent extends EventObject {
+
+ private static final long serialVersionUID = 1330139373403204421L;
+
+ public static final int FILE_ADDED = 0;
+ public static final int FILE_CHANGED = 1;
+ public static final int FILE_REMOVED = 2;
+
+ private final File file;
+ private final int type;
+ public DeploymentEvent(File file, int type) {
+ super(file);
+ this.file = file;
+ this.type = type;
+ }
+
+ /**
+ * @return the file
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * @return the type
+ */
+ public int getType() {
+ return type;
+ }
+
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentEvent.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentEvent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentListener.java?view=auto&rev=492735
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentListener.java (added)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentListener.java Thu Jan 4 12:57:08 2007
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.event;
+
+import java.io.IOException;
+import java.util.EventListener;
+
+public interface DeploymentListener extends EventListener {
+
+ public boolean fileAdded(DeploymentEvent event) throws IOException;
+
+ public boolean fileChanged(DeploymentEvent event) throws IOException;
+
+ public boolean fileRemoved(DeploymentEvent event) throws IOException;
+}
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentListener.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/event/DeploymentListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java?view=diff&rev=492735&r1=492734&r2=492735
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java Thu Jan 4 12:57:08 2007
@@ -44,6 +44,8 @@
import org.apache.servicemix.jbi.deployment.Descriptor;
import org.apache.servicemix.jbi.deployment.DescriptorFactory;
import org.apache.servicemix.jbi.deployment.ServiceAssembly;
+import org.apache.servicemix.jbi.event.DeploymentEvent;
+import org.apache.servicemix.jbi.event.DeploymentListener;
import org.apache.servicemix.jbi.management.AttributeInfoHelper;
import org.apache.servicemix.jbi.management.BaseSystemService;
import org.apache.servicemix.jbi.util.FileUtil;
@@ -66,6 +68,7 @@
private boolean monitorInstallationDirectory = true;
private boolean monitorDeploymentDirectory = true;
private int monitorInterval = 10;
+ private String extensions = ".zip,.jar";
private AtomicBoolean started = new AtomicBoolean(false);
private Timer statsTimer;
private TimerTask timerTask;
@@ -75,6 +78,20 @@
private Map deployFileMap = null;
/**
+ * @return the extensions
+ */
+ public String getExtensions() {
+ return extensions;
+ }
+
+ /**
+ * @param extensions the extensions to set
+ */
+ public void setExtensions(String extensions) {
+ this.extensions = extensions;
+ }
+
+ /**
* @return a description of this
*/
public String getDescription(){
@@ -193,6 +210,19 @@
* @throws DeploymentException
*/
public void updateArchive(String location, ArchiveEntry entry, boolean autoStart) throws DeploymentException {
+ // Call listeners
+ try {
+ DeploymentListener[] listeners = (DeploymentListener[]) container.getListeners(DeploymentListener.class);
+ DeploymentEvent event = new DeploymentEvent(new File(location), DeploymentEvent.FILE_CHANGED);
+ for (int i = 0; i < listeners.length; i++) {
+ if (listeners[i].fileChanged(event)) {
+ return;
+ }
+ }
+ } catch (IOException e) {
+ throw failure("deploy", "Error when deploying: " + location, e);
+ }
+ // Standard processing
File tmpDir = null;
try {
tmpDir = AutoDeploymentService.unpackLocation(environmentContext.getTmpDir(), location);
@@ -369,6 +399,19 @@
* @throws DeploymentException
*/
public void removeArchive(ArchiveEntry entry) throws DeploymentException {
+ // Call listeners
+ try {
+ DeploymentListener[] listeners = (DeploymentListener[]) container.getListeners(DeploymentListener.class);
+ DeploymentEvent event = new DeploymentEvent(new File(entry.location), DeploymentEvent.FILE_REMOVED);
+ for (int i = 0; i < listeners.length; i++) {
+ if (listeners[i].fileRemoved(event)) {
+ return;
+ }
+ }
+ } catch (IOException e) {
+ throw failure("deploy", "Error when deploying: " + entry.location, e);
+ }
+ // Standard processing
log.info("Attempting to remove archive at: " + entry.location);
try{
container.getBroker().suspend();
@@ -527,7 +570,7 @@
try{
URL url = new URL(location);
String fileName = url.getFile();
- if (fileName == null || (!fileName.endsWith(".zip") && !fileName.endsWith(".jar"))) {
+ if (fileName == null) {
throw new DeploymentException("Location: " + location + " is not an archive");
}
file = FileUtil.unpackArchive(url,tmpRoot);
@@ -572,12 +615,16 @@
}
- private void monitorDirectory(final File root,final Map fileMap){
- if(root!=null)
- log.debug("Monitoring directory "+root.getAbsolutePath()+" for new or modified archives");
- else
- log.debug("No directory to monitor for new or modified archives for "+""
- +((fileMap==installFileMap)?"Installation":"Deployment")+".");
+ private void monitorDirectory(final File root, final Map fileMap) {
+ /*
+ if (log.isTraceEnabled()) {
+ if (root != null)
+ log.trace("Monitoring directory " + root.getAbsolutePath() + " for new or modified archives");
+ else
+ log.trace("No directory to monitor for new or modified archives for "
+ + ((fileMap==installFileMap) ? "Installation" : "Deployment") + ".");
+ }
+ */
List tmpList=new ArrayList();
if(root!=null&&root.exists()&&root.isDirectory()){
File[] files=root.listFiles();
@@ -585,7 +632,7 @@
for(int i=0;i<files.length;i++){
final File file=files[i];
tmpList.add(file.getName());
- if(file.getPath().endsWith(".jar")||file.getPath().endsWith(".zip")){
+ if (isAllowedExtension(file.getName())) {
ArchiveEntry lastEntry = (ArchiveEntry) fileMap.get(file.getName());
if(lastEntry == null || file.lastModified() > lastEntry.lastModified.getTime()){
try{
@@ -626,6 +673,16 @@
persistState(root, fileMap);
}
}
+ }
+
+ private boolean isAllowedExtension(String file) {
+ String[] extensions = this.extensions.split(",");
+ for (int i = 0; i < extensions.length; i++) {
+ if (file.endsWith(extensions[i])) {
+ return true;
+ }
+ }
+ return false;
}
private void persistState(File root, Map map) {