Skip to content

Commit

Permalink
[#461] Capacity and increase/decrease policies - adding classloading SPI
Browse files Browse the repository at this point in the history
  • Loading branch information
maeste committed Mar 15, 2016
1 parent a8d5ba2 commit a3c6e27
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 2 deletions.
Expand Up @@ -23,6 +23,7 @@

import org.ironjacamar.common.api.metadata.resourceadapter.Activation;
import org.ironjacamar.common.api.metadata.spec.Connector;
import org.ironjacamar.core.spi.classloading.ClassLoaderPlugin;

import java.io.File;
import java.util.Collection;
Expand Down Expand Up @@ -87,6 +88,13 @@ public interface Deployment
*/
public Collection<AdminObject> getAdminObjects();

/**
* Get the class loader plugin
*
* @return The value
*/
public ClassLoaderPlugin getClassLoaderPlugin();

/**
* Is the deployment active ?
* @return <code>true</code> if activated, <code>false</code> if not
Expand Down
@@ -0,0 +1,39 @@
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2016, Red Hat Inc, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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 Eclipse Public License 1.0 as
* published by the Free Software Foundation.
*
* 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 Eclipse
* Public License for more details.
*
* You should have received a copy of the Eclipse 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.ironjacamar.core.classloading;

import org.ironjacamar.core.spi.classloading.ClassLoaderPlugin;

/** The default inplementation of SPI for class loading
* This implementation is just using container classloading, ignoring any module parameters
*
* @author <a href="mailto:stefano.maestri@ironjacamar.org">Stefano Maestri</a>
*/

public class IronJacamarClassLoaderPlugin implements ClassLoaderPlugin
{
@Override
public Class<?> loadClass(String className, String moduleName, String moduleSlot) throws ClassNotFoundException
{
return SecurityActions.getClassLoader(IronJacamarClassLoaderPlugin.class).loadClass(className);
}
}
@@ -0,0 +1,52 @@
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2016, Red Hat Inc, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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 Eclipse Public License 1.0 as
* published by the Free Software Foundation.
*
* 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 Eclipse
* Public License for more details.
*
* You should have received a copy of the Eclipse 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.ironjacamar.core.classloading;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* Privileged Blocks
* @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
*/
class SecurityActions
{
/**
* Constructor
*/
private SecurityActions()
{
}

/**
* Get the classloader.
* @param c The class
* @return The classloader
*/
static ClassLoader getClassLoader(final Class<?> c)
{
if (System.getSecurityManager() == null)
return c.getClassLoader();

return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> c.getClassLoader());
}
}
@@ -0,0 +1,25 @@
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2016, Red Hat Inc, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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 Eclipse Public License 1.0 as
* published by the Free Software Foundation.
*
* 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 Eclipse
* Public License for more details.
*
* You should have received a copy of the Eclipse 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.
*/

/**
* Created by maeste on 3/15/16.
*/
package org.ironjacamar.core.classloading;
Expand Up @@ -27,6 +27,7 @@
import org.ironjacamar.core.api.deploymentrepository.ConnectionFactory;
import org.ironjacamar.core.api.deploymentrepository.Deployment;
import org.ironjacamar.core.api.deploymentrepository.ResourceAdapter;
import org.ironjacamar.core.spi.classloading.ClassLoaderPlugin;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -66,6 +67,10 @@ public class DeploymentBuilder
/** The admin objects */
private Collection<AdminObject> adminObjects;

/**The class loader plugin */
private ClassLoaderPlugin classLoaderPlugin;


/**
* Constructor
*/
Expand All @@ -80,6 +85,7 @@ public DeploymentBuilder()
this.resourceAdapter = null;
this.connectionFactories = null;
this.adminObjects = null;
this.classLoaderPlugin = null;
}

/**
Expand Down Expand Up @@ -162,6 +168,17 @@ public DeploymentBuilder classLoader(ClassLoader v)
return this;
}

/**
* Set class loader plugin
* @param v The value
* @return The builder
*/
public DeploymentBuilder classLoaderPlugin(ClassLoaderPlugin v)
{
classLoaderPlugin = v;
return this;
}

/**
* Get metadata
* @return The value
Expand Down Expand Up @@ -282,6 +299,6 @@ public Deployment build()
{
return new DeploymentImpl(identifier, name, archive, classLoader,
metadata, activation,
resourceAdapter, getConnectionFactories(), getAdminObjects());
resourceAdapter, getConnectionFactories(), getAdminObjects(), classLoaderPlugin);
}
}
Expand Up @@ -27,6 +27,7 @@
import org.ironjacamar.core.api.deploymentrepository.ConnectionFactory;
import org.ironjacamar.core.api.deploymentrepository.Deployment;
import org.ironjacamar.core.api.deploymentrepository.ResourceAdapter;
import org.ironjacamar.core.spi.classloading.ClassLoaderPlugin;

import java.io.File;
import java.util.Collection;
Expand Down Expand Up @@ -67,6 +68,9 @@ public class DeploymentImpl implements Deployment
/** The admin objects */
private Collection<AdminObject> adminObjects;

/**The class loader plugin */
private ClassLoaderPlugin classLoaderPlugin;

/**
* Constructor
* @param identifier The identifier
Expand All @@ -78,6 +82,7 @@ public class DeploymentImpl implements Deployment
* @param resourceAdapter The resource adapter
* @param connectionFactories The connection factories
* @param adminObjects The admin objects
* @param classLoaderPlugin the class loader plugin
*/
public DeploymentImpl(String identifier,
String name,
Expand All @@ -87,7 +92,8 @@ public DeploymentImpl(String identifier,
Activation activation,
ResourceAdapter resourceAdapter,
Collection<ConnectionFactory> connectionFactories,
Collection<AdminObject> adminObjects)
Collection<AdminObject> adminObjects,
ClassLoaderPlugin classLoaderPlugin)
{
this.activated = false;
this.identifier = identifier;
Expand All @@ -99,6 +105,7 @@ public DeploymentImpl(String identifier,
this.resourceAdapter = resourceAdapter;
this.connectionFactories = connectionFactories;
this.adminObjects = adminObjects;
this.classLoaderPlugin = classLoaderPlugin;
}

/**
Expand Down Expand Up @@ -173,6 +180,15 @@ public Collection<AdminObject> getAdminObjects()
return adminObjects;
}

/**
*{@inheritDoc}
*/
@Override
public ClassLoaderPlugin getClassLoaderPlugin()
{
return classLoaderPlugin;
}

/**
* {@inheritDoc}
*/
Expand Down
@@ -0,0 +1,40 @@
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2016, Red Hat Inc, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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 Eclipse Public License 1.0 as
* published by the Free Software Foundation.
*
* 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 Eclipse
* Public License for more details.
*
* You should have received a copy of the Eclipse 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.ironjacamar.core.spi.classloading;

/** The SPI for class loading
*
* @author <a href="mailto:stefano.maestri@ironjacamar.org">Stefano Maestri</a>
*/
public interface ClassLoaderPlugin
{
/**
* load class using plugged in ClassLoader
* @param className the class name
* @param moduleName the module name
* @param moduleSlot the module slot
* @return the class
* @@throws ClassNotFoundException
* If the class could not be found
*/
public Class<?> loadClass(String className, String moduleName, String moduleSlot) throws ClassNotFoundException;
}
@@ -0,0 +1,25 @@
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2016, Red Hat Inc, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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 Eclipse Public License 1.0 as
* published by the Free Software Foundation.
*
* 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 Eclipse
* Public License for more details.
*
* You should have received a copy of the Eclipse 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.
*/

/**
* Created by maeste on 3/14/16.
*/
package org.ironjacamar.core.spi.classloading;
Expand Up @@ -50,6 +50,7 @@
import org.ironjacamar.core.deploymentrepository.ResourceAdapterImpl;
import org.ironjacamar.core.metadatarepository.MetadataImpl;
import org.ironjacamar.core.recovery.DefaultRecoveryPlugin;
import org.ironjacamar.core.spi.classloading.ClassLoaderPlugin;
import org.ironjacamar.core.spi.naming.JndiStrategy;
import org.ironjacamar.core.spi.recovery.RecoveryPlugin;
import org.ironjacamar.core.spi.security.SubjectFactory;
Expand Down Expand Up @@ -96,6 +97,9 @@ public abstract class AbstractResourceAdapterDeployer
/** The Subject Factory */
protected SubjectFactory subjectFactory;

/** The Subject Factory */
protected ClassLoaderPlugin classLoaderPlugin;

/** The default pool type */
protected String defaultPoolType;

Expand Down Expand Up @@ -168,6 +172,16 @@ public void setSubjectFactory(SubjectFactory subjectFactory)
this.subjectFactory = subjectFactory;
}

/**
* Set the class loader plugin
* @param classLoaderPlugin The value
*/
public void setClassLoaderPlugin(ClassLoaderPlugin classLoaderPlugin)
{
this.classLoaderPlugin = classLoaderPlugin;
}


/**
* Set the cached connection manager
* @param v The value
Expand Down Expand Up @@ -226,6 +240,7 @@ public Deployment activate(Connector connector, Activation activation, ClassLoad

builder.archive(md.getArchive());
builder.classLoader(cl);
builder.classLoaderPlugin(classLoaderPlugin);

if (connector.getResourceadapter().getResourceadapterClass() != null)
createResourceAdapter(builder, connector.getResourceadapter().getResourceadapterClass(),
Expand Down
Expand Up @@ -160,6 +160,7 @@ public Deployer clone() throws CloneNotSupportedException
d.setTransactionIntegration(transactionIntegration);
d.setCachedConnectionManager(cachedConnectionManager);
d.setSubjectFactory(subjectFactory);
d.setClassLoaderPlugin(classLoaderPlugin);
d.setDefaultPoolType(defaultPoolType);
return d;
}
Expand Down
Expand Up @@ -141,6 +141,7 @@ public Deployer clone() throws CloneNotSupportedException
i.setTransactionIntegration(transactionIntegration);
i.setCachedConnectionManager(cachedConnectionManager);
i.setSubjectFactory(subjectFactory);
i.setClassLoaderPlugin(classLoaderPlugin);
i.setDefaultPoolType(defaultPoolType);
return i;
}
Expand Down

0 comments on commit a3c6e27

Please sign in to comment.