[jboss-cvs] JBossAS SVN: r60185 - in trunk/system/src/main/org/jboss: profileservice/aop and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Feb 2 04:18:50 EST 2007
Author: scott.stark at jboss.org
Date: 2007-02-02 04:18:50 -0500 (Fri, 02 Feb 2007)
New Revision: 60185
Added:
trunk/system/src/main/org/jboss/system/server/profileservice/repository/TCLObjectInputStream.java
Modified:
trunk/system/src/main/org/jboss/deployers/spi/management/ManagedDeployment.java
trunk/system/src/main/org/jboss/deployers/spi/management/ManagementView.java
trunk/system/src/main/org/jboss/profileservice/aop/DeployerAspects.java
trunk/system/src/main/org/jboss/profileservice/aop/TrackingAdvice.java
trunk/system/src/main/org/jboss/profileservice/spi/AttachmentsSerializer.java
trunk/system/src/main/org/jboss/system/server/profile/repository/ProfileImpl.java
trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractFileAttachmentsSerializer.java
trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaSerializationAttachmentsSerializer.java
trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
Log:
Update the profile service interfaces/aspects
Modified: trunk/system/src/main/org/jboss/deployers/spi/management/ManagedDeployment.java
===================================================================
--- trunk/system/src/main/org/jboss/deployers/spi/management/ManagedDeployment.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/deployers/spi/management/ManagedDeployment.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -37,7 +37,20 @@
*/
public interface ManagedDeployment
{
+ /**
+ * Get the full name of the associated DeploymentUnit.
+ * @return full name of the DeploymentUnit
+ */
public String getName();
+ /**
+ * Get the simple name (x.ear) for the deployment
+ * @return simple name of the deployment
+ */
+ public String getSimpleName();
+ /**
+ * Get the phase this deployment is associated with
+ * @return
+ */
public DeploymentPhase getDeploymentPhase();
/**
* Get the deployment/module types.
Modified: trunk/system/src/main/org/jboss/deployers/spi/management/ManagementView.java
===================================================================
--- trunk/system/src/main/org/jboss/deployers/spi/management/ManagementView.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/deployers/spi/management/ManagementView.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -103,6 +103,14 @@
throws Exception;
/**
+ *
+ * @param comp
+ * @throws Exception
+ */
+ public void updateComponent(ManagedComponent comp)
+ throws Exception;
+
+ /**
* Get the registered DeploymentTemplate names.
*
* TODO: probably needs a Map<String, DeploymentType> notion
Modified: trunk/system/src/main/org/jboss/profileservice/aop/DeployerAspects.java
===================================================================
--- trunk/system/src/main/org/jboss/profileservice/aop/DeployerAspects.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/profileservice/aop/DeployerAspects.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -21,13 +21,18 @@
*/
package org.jboss.profileservice.aop;
+import java.util.Map;
+
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.deployers.spi.deployer.Deployer;
import org.jboss.deployers.spi.deployer.DeploymentUnit;
import org.jboss.deployers.spi.management.ComponentType;
import org.jboss.deployers.spi.management.ComponentTypeListener;
import org.jboss.deployers.spi.management.ComponentTypeVisitor;
+import org.jboss.deployers.spi.structure.DeploymentContext;
import org.jboss.logging.Logger;
+import org.jboss.profileservice.spi.AttachmentsSerializer;
/**
* Aspects that integrate with the profile service.
@@ -43,6 +48,7 @@
*/
private static ComponentTypeVisitor compVisitor;
private static ComponentTypeListener compListener;
+ private static AttachmentsSerializer attachmentsSerializer;
public static ComponentTypeVisitor getCompVisitor()
{
@@ -66,6 +72,15 @@
DeployerAspects.compListener = compListener;
}
+ public static AttachmentsSerializer getAttachmentsSerializer()
+ {
+ return attachmentsSerializer;
+ }
+ public static void setAttachmentsSerializer(
+ AttachmentsSerializer attachmentsSerializer)
+ {
+ DeployerAspects.attachmentsSerializer = attachmentsSerializer;
+ }
public String getName()
{
return this.getClass().getName();
@@ -90,12 +105,52 @@
return value;
}
+ /**
+ *
+ * @param invocation
+ * @return
+ * @throws Throwable
+ */
public Object prepareDeploy(MethodInvocation invocation)
throws Throwable
{
- Object target = invocation.getTargetObject();
+ Deployer target = Deployer.class.cast(invocation.getTargetObject());
Object[] args = invocation.getArguments();
- log.debug("prepareDeploy, target="+target);
+ DeploymentUnit unit = DeploymentUnit.class.cast(args[0]);
+ log.debug("prepareDeploy, target="+target+", unit="+unit.getSimpleName());
+ if( attachmentsSerializer != null )
+ {
+ ClassLoader loader = null;
+ try
+ {
+ loader = unit.getClassLoader();
+ }
+ catch(Exception ignore)
+ {
+ }
+ ClassLoader prevTCL = Thread.currentThread().getContextClassLoader();
+ if( loader == null )
+ loader = prevTCL;
+ DeploymentContext ctx = unit.getDeploymentContext();
+ // No guarentee this is unique
+ String deployerID = target.getClass().getSimpleName();
+ try
+ {
+ Map<String, Object> map = attachmentsSerializer.loadAttachments(ctx, deployerID, loader);
+ if( map != null )
+ {
+ for(String key : map.keySet())
+ {
+ Object value = map.get(key);
+ ctx.getPredeterminedManagedObjects().addAttachment(key, value);
+ }
+ }
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(prevTCL);
+ }
+ }
return invocation.invokeNext();
}
public Object commitDeploy(MethodInvocation invocation)
@@ -103,17 +158,43 @@
{
Object value = invocation.invokeNext();
Object[] args = invocation.getArguments();
- DeploymentUnit unit = (DeploymentUnit) args[0];
- log.debug("commitDeploy, unit="+unit);
+ Deployer target = Deployer.class.cast(invocation.getTargetObject());
+ DeploymentUnit unit = DeploymentUnit.class.cast(args[0]);
+ log.debug("commitDeploy, target="+target+", unit="+unit.getSimpleName());
if( compVisitor != null )
{
ComponentType type = compVisitor.visit(unit);
if( type != null && compListener != null )
compListener.updateComponentType(unit, type);
}
+ if( attachmentsSerializer != null )
+ {
+ ClassLoader loader = null;
+ try
+ {
+ loader = unit.getClassLoader();
+ }
+ catch(Exception ignore)
+ {
+ }
+ ClassLoader prevTCL = Thread.currentThread().getContextClassLoader();
+ if( loader == null )
+ loader = prevTCL;
+ DeploymentContext ctx = unit.getDeploymentContext();
+ // No guarentee this is unique
+ String deployerID = target.getClass().getSimpleName();
+ try
+ {
+ attachmentsSerializer.saveAttachments(ctx, deployerID, loader);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(prevTCL);
+ }
+ }
return value;
}
-
+
public Object prepareUndeploy(MethodInvocation invocation)
throws Throwable
{
Modified: trunk/system/src/main/org/jboss/profileservice/aop/TrackingAdvice.java
===================================================================
--- trunk/system/src/main/org/jboss/profileservice/aop/TrackingAdvice.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/profileservice/aop/TrackingAdvice.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -113,6 +113,8 @@
public static Map<String, Object> clearAttachmentsForTarget(Object key)
{
Map<String, Object> attachments = attachmentsByTarget.remove(key);
+ if( log.isTraceEnabled() )
+ log.trace("clearAttachmentsForTarget, target="+key+" :"+attachments);
return attachments;
}
@@ -125,6 +127,7 @@
attachmentsByTarget.put(target, attachments);
}
attachments.put(name, attachment);
+ log.debug("addAttachment, target="+target+", name="+name);
}
private static void removeAttachment(Object target, String name)
{
@@ -135,6 +138,7 @@
if( attachments.size() == 0 )
attachmentsByTarget.remove(target);
}
+ log.debug("removeAttachment, target="+target+", name="+name);
}
/**
Modified: trunk/system/src/main/org/jboss/profileservice/spi/AttachmentsSerializer.java
===================================================================
--- trunk/system/src/main/org/jboss/profileservice/spi/AttachmentsSerializer.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/profileservice/spi/AttachmentsSerializer.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -34,6 +34,8 @@
*/
public interface AttachmentsSerializer
{
- public void saveAttachments(DeploymentContext ctx) throws Exception;
- public Map<String, Object> loadAttachments(DeploymentContext ctx) throws Exception;
+ public void saveAttachments(DeploymentContext ctx, String deployerID, ClassLoader loader)
+ throws Exception;
+ public Map<String, Object> loadAttachments(DeploymentContext ctx, String deployerID, ClassLoader loader)
+ throws Exception;
}
Modified: trunk/system/src/main/org/jboss/system/server/profile/repository/ProfileImpl.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profile/repository/ProfileImpl.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/system/server/profile/repository/ProfileImpl.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -110,7 +110,10 @@
public void addDeployment(DeploymentContext d, DeploymentPhase phase)
throws Exception
{
- repository.addDeployment(d.getRelativePath(), d, phase);
+ String name = d.getRelativePath();
+ if( name.length() == 0 )
+ name = d.getSimpleName();
+ repository.addDeployment(name, d, phase);
}
public void updateDeployment(DeploymentContext d, DeploymentPhase phase)
throws Exception
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractFileAttachmentsSerializer.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractFileAttachmentsSerializer.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractFileAttachmentsSerializer.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -26,6 +26,7 @@
import java.util.Map;
import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.profileservice.aop.TrackingAdvice;
import org.jboss.profileservice.spi.AttachmentsSerializer;
/**
@@ -49,7 +50,8 @@
this.attachmentsStoreDir = attachmentsStoreDir;
}
- public Map<String, Object> loadAttachments(DeploymentContext ctx) throws Exception
+ public Map<String, Object> loadAttachments(DeploymentContext ctx, String deployerID, ClassLoader loader)
+ throws Exception
{
if( attachmentsStoreDir == null )
throw new IllegalStateException("attachmentsStoreDir has not been set");
@@ -58,16 +60,18 @@
if( vfsPath.length() == 0 )
vfsPath = ctx.getSimpleName();
vfsPath += ".attachments";
- File attachmentsStore = new File(attachmentsStoreDir, vfsPath);
+ File deployerDir = new File(attachmentsStoreDir, deployerID);
+ File attachmentsStore = new File(deployerDir, vfsPath);
if( attachmentsStore.exists() == false )
{
return null;
}
- return loadAttachments(attachmentsStore, ctx);
+ return loadAttachments(attachmentsStore, loader);
}
- public void saveAttachments(DeploymentContext ctx) throws Exception
+ public void saveAttachments(DeploymentContext ctx, String deployerID, ClassLoader loader)
+ throws Exception
{
if( attachmentsStoreDir == null )
throw new IllegalStateException("attachmentsStoreDir has not been set");
@@ -76,7 +80,8 @@
if( vfsPath.length() == 0 )
vfsPath = ctx.getSimpleName();
vfsPath += ".attachments";
- File attachmentsStore = new File(attachmentsStoreDir, vfsPath);
+ File deployerDir = new File(attachmentsStoreDir, deployerID);
+ File attachmentsStore = new File(deployerDir, vfsPath);
File attachmentsParent = attachmentsStore.getParentFile();
if( attachmentsParent.exists() == false )
{
@@ -84,11 +89,13 @@
throw new IOException("Failed to create attachmentsParent: "+attachmentsParent.getAbsolutePath());
}
- saveAttachments(attachmentsStore, ctx);
+ Map<String, Object> attachments = TrackingAdvice.clearAttachmentsForTarget(ctx.getTransientManagedObjects());
+ if( attachments != null )
+ saveAttachments(attachmentsStore, attachments, loader);
}
- protected abstract Map<String, Object> loadAttachments(File attachmentsStore, DeploymentContext ctx)
+ protected abstract Map<String, Object> loadAttachments(File attachmentsStore, ClassLoader loader)
throws Exception;
- protected abstract void saveAttachments(File attachmentsStore, DeploymentContext ctx)
+ protected abstract void saveAttachments(File attachmentsStore, Map<String, Object> attachments, ClassLoader loader)
throws Exception;
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaSerializationAttachmentsSerializer.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaSerializationAttachmentsSerializer.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaSerializationAttachmentsSerializer.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -26,10 +26,12 @@
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.Arrays;
import java.util.Map;
-import org.jboss.deployers.spi.attachments.Attachments;
-import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.logging.Logger;
/**
* Standard java serialization to a file.
@@ -40,23 +42,38 @@
public class JavaSerializationAttachmentsSerializer
extends AbstractFileAttachmentsSerializer
{
+ private static final Logger log = Logger.getLogger(JavaSerializationAttachmentsSerializer.class);
- protected Map<String, Object> loadAttachments(File attachmentsStore, DeploymentContext ctx)
+ protected Map<String, Object> loadAttachments(File attachmentsStore, ClassLoader loader)
throws Exception
{
+ Thread.currentThread().setContextClassLoader(loader);
FileInputStream fis = new FileInputStream(attachmentsStore);
- ObjectInputStream ois = new ObjectInputStream(fis);
- Map<String, Object> map = (Map<String, Object>) ois.readObject();
- ois.close();
- fis.close();
+ ObjectInputStream ois = new TCLObjectInputStream(fis, loader);
+ Map<String, Object> map = null;
+ try
+ {
+ map = (Map<String, Object>) ois.readObject();
+ }
+ catch(ClassNotFoundException e)
+ {
+ URL[] path = getClassLoaderURLs(loader);
+ log.debug("ClassNotFoundException: "+e.getMessage()+", path: "+Arrays.asList(path));
+ }
+ finally
+ {
+ if( ois != null )
+ ois.close();
+ if( fis != null )
+ fis.close();
+ }
return map;
}
- protected void saveAttachments(File attachmentsStore, DeploymentContext ctx)
+ protected void saveAttachments(File attachmentsStore,
+ Map<String, Object> map, ClassLoader loader)
throws Exception
{
- Attachments transientAttachments = ctx.getTransientManagedObjects();
- Map<String, Object> map = transientAttachments.getAttachments();
FileOutputStream fos = new FileOutputStream(attachmentsStore);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(map);
@@ -64,4 +81,66 @@
fos.close();
}
+ /** Use reflection to access a URL[] getURLs or URL[] getClasspath method so
+ that non-URLClassLoader class loaders, or class loaders that override
+ getURLs to return null or empty, can provide the true classpath info.
+ */
+ private static URL[] getClassLoaderURLs(ClassLoader cl)
+ {
+ URL[] urls = {};
+ try
+ {
+ Class returnType = urls.getClass();
+ Class[] parameterTypes = {};
+ Class clClass = cl.getClass();
+ Method getURLs = clClass.getMethod("getURLs", parameterTypes);
+ if( returnType.isAssignableFrom(getURLs.getReturnType()) )
+ {
+ Object[] args = {};
+ urls = (URL[]) getURLs.invoke(cl, args);
+ }
+ }
+ catch(Exception ignore)
+ {
+ }
+ if( urls == null || urls.length == 0 )
+ {
+ try
+ {
+ Class returnType = urls.getClass();
+ Class[] parameterTypes = {};
+ Class clClass = cl.getClass();
+ Method getURLs = clClass.getMethod("getAllURLs", parameterTypes);
+ if( returnType.isAssignableFrom(getURLs.getReturnType()) )
+ {
+ Object[] args = {};
+ urls = (URL[]) getURLs.invoke(cl, args);
+ }
+ }
+ catch(Exception ignore)
+ {
+ }
+ }
+ if( urls == null || urls.length == 0 )
+ {
+ try
+ {
+ Class returnType = urls.getClass();
+ Class[] parameterTypes = {};
+ Class clClass = cl.getClass();
+ Method getURLs = clClass.getMethod("getClasspath", parameterTypes);
+ if( returnType.isAssignableFrom(getURLs.getReturnType()) )
+ {
+ Object[] args = {};
+ urls = (URL[]) getURLs.invoke(cl, args);
+ }
+ }
+ catch(Exception ignore)
+ {
+ }
+ }
+
+ return urls;
+ }
+
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java 2007-02-02 09:15:41 UTC (rev 60184)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -219,18 +219,6 @@
public void updateDeployment(String vfsPath, DeploymentContext d, DeploymentPhase phase)
throws Exception
{
- Attachments pmos = d.getPredeterminedManagedObjects();
- if( pmos != null && pmos.hasAttachments() == true )
- return;
- try
- {
- saveAttachments(d);
- }
- catch(NotSerializableException e)
- {
- log.warn("Failed to save attachments for: "+d.getName()+", "+e);
- }
-
}
public DeploymentContext getDeployment(String name, DeploymentPhase phase)
throws Exception, NoSuchDeploymentException
@@ -443,8 +431,6 @@
throws Exception
{
this.bootstrapCtxs.put(vfsPath, ctx);
- // Write out the base transient metadata
- saveAttachments(ctx);
}
// Managed object attachments for a deployment
@@ -464,16 +450,12 @@
throws Exception
{
this.deployerCtxs.put(vfsPath, ctx);
- // Write out the base transient metadata
- saveAttachments(ctx);
}
protected void addApplication(String vfsPath, DeploymentContext ctx)
throws Exception
{
this.applicationCtxs.put(vfsPath, ctx);
- // Write out the base transient metadata
- saveAttachments(ctx);
}
protected DeploymentContext getBootstrap(String vfsPath)
@@ -593,23 +575,13 @@
applicationDir = new File(uri);
}
- private void saveAttachments(DeploymentContext ctx)
- throws Exception
- {
- // Write out the base transient metadata
- serializer.saveAttachments(ctx);
- }
-
private void loadAttachments(DeploymentContext ctx)
throws Exception
{
ClassLoader prevTCL = Thread.currentThread().getContextClassLoader();
try
{
- ClassLoader loader = ctx.getClassLoader();
- if( loader != null )
- Thread.currentThread().setContextClassLoader(loader);
- Map<String, Object> map = serializer.loadAttachments(ctx);
+ Map<String, Object> map = null; //serializer.loadAttachments(ctx, prevTCL);
if( map != null )
{
for(String key : map.keySet())
Added: trunk/system/src/main/org/jboss/system/server/profileservice/repository/TCLObjectInputStream.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/TCLObjectInputStream.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/TCLObjectInputStream.java 2007-02-02 09:18:50 UTC (rev 60185)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.repository;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Use the TCL to load a class on a CNFE as the ObjectInputStream
+ * fails to use this
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class TCLObjectInputStream
+ extends ObjectInputStream
+{
+ private static Logger log = Logger.getLogger(TCLObjectInputStream.class);
+ private ClassLoader loader;
+
+ public TCLObjectInputStream(InputStream in, ClassLoader loader)
+ throws IOException
+ {
+ super(in);
+ this.loader = loader;
+ }
+
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc)
+ throws IOException, ClassNotFoundException
+ {
+ String name = desc.getName();
+ try
+ {
+ return super.resolveClass(desc);
+ }
+ catch(ClassNotFoundException e)
+ {
+ log.debug("ClassNotFoundException for name="+name+", retrying using TCL");
+ return Class.forName(name, false, loader);
+ }
+ }
+
+}
Property changes on: trunk/system/src/main/org/jboss/system/server/profileservice/repository/TCLObjectInputStream.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list