Skip to content

Commit

Permalink
[#461] Capacity and increase/decrease policies
Browse files Browse the repository at this point in the history
  • Loading branch information
maeste committed Mar 30, 2016
1 parent c783989 commit ab1d3b9
Show file tree
Hide file tree
Showing 37 changed files with 2,224 additions and 19 deletions.
@@ -0,0 +1,42 @@
/*
* 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.api.connectionmanager.pool;

import org.ironjacamar.core.connectionmanager.listener.ConnectionListener;

/**
* The capacity decrementer policy
*
* @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
*/
public interface CapacityDecrementer
{
/**
* Should the connection listener be destroyed
* @param cl The connection listener
* @param timeout The timeout watermark
* @param currentSize The current pool size
* @param minPoolSize The minimum pool size
* @param destroyed The number of connection listeners destroyed during this call cycle
* @return <code>True</code> if the connection listener should be destroyed; otherwise <code>false</code>
*/
public boolean shouldDestroy(ConnectionListener cl, long timeout, int currentSize, int minPoolSize, int destroyed);
}
@@ -0,0 +1,38 @@
/*
* 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.api.connectionmanager.pool;

/**
* The capacity incrementer policy
*
* @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
*/
public interface CapacityIncrementer
{
/**
* Should the connection listener be created
* @param currentSize The current pool size
* @param maxSize The maximum pool size
* @param created The number of connection listeners created during this call cycle
* @return <code>True</code> if a connection listener should be created; otherwise <code>false</code>
*/
public boolean shouldCreate(int currentSize, int maxSize, int created);
}
Expand Up @@ -21,6 +21,8 @@

package org.ironjacamar.core.api.deploymentrepository;

import org.ironjacamar.core.api.connectionmanager.pool.CapacityDecrementer;
import org.ironjacamar.core.api.connectionmanager.pool.CapacityIncrementer;
import org.ironjacamar.core.spi.statistics.StatisticsPlugin;

/**
Expand All @@ -40,4 +42,16 @@ public interface Pool
* @return The value
*/
public StatisticsPlugin getStatistics();

/**
* Get the capacityIncrementer
* @return The value
*/
public CapacityIncrementer getCapacityIncrementer();

/**
* Get the capacityDecrementer
* @return The value
*/
public CapacityDecrementer getCapacityDecrementer();
}
Expand Up @@ -32,10 +32,10 @@ public class DistributableContext implements WorkContext
private static final long serialVersionUID = 1L;

/** The distribute key */
public static final String DISTRIBUTE = "org.jboss.jca.core.api.workmanager.Distribute";
public static final String DISTRIBUTE = "org.ironjacamar.core.api.workmanager.Distribute";

/** The workmanager key */
public static final String WORKMANAGER = "org.jboss.jca.core.api.workmanager.WorkManager";
public static final String WORKMANAGER = "org.ironjacamar.core.api.workmanager.WorkManager";

private Boolean distribute;
private String workManager;
Expand Down
Expand Up @@ -148,4 +148,50 @@ public Boolean run()

return equals.booleanValue();
}

/**
* 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(new PrivilegedAction<ClassLoader>()
{
public ClassLoader run()
{
return c.getClassLoader();
}
});
}

/**
* Set the context classloader.
*
* @param cl classloader
*/
public static void setThreadContextClassLoader(final ClassLoader cl)
{
if (System.getSecurityManager() == null)
{
Thread.currentThread().setContextClassLoader(cl);
}
else
{
AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
Thread.currentThread().setContextClassLoader(cl);

return null;
}
});
}
}

}
Expand Up @@ -50,6 +50,12 @@ public abstract class AbstractManagedConnectionPool implements ManagedConnection
/** The credential */
protected Credential credential;

/** pool is fifo*/
protected final boolean poolIsFifo;

/** last idle check */
protected long lastIdleCheck;

/**
* Constructor
* @param pool The pool
Expand All @@ -59,6 +65,8 @@ public AbstractManagedConnectionPool(Pool pool, Credential credential)
{
this.pool = pool;
this.credential = credential;
poolIsFifo = pool.isFIFO() && credential.equals(pool.getPrefillCredential());
this.lastIdleCheck = System.currentTimeMillis();
}

/**
Expand Down
Expand Up @@ -28,6 +28,8 @@
import org.ironjacamar.core.connectionmanager.Credential;
import org.ironjacamar.core.connectionmanager.TransactionalConnectionManager;
import org.ironjacamar.core.connectionmanager.listener.ConnectionListener;
import org.ironjacamar.core.connectionmanager.pool.capacity.DefaultCapacity;
import org.ironjacamar.core.connectionmanager.pool.capacity.TimedOutDecrementer;
import org.ironjacamar.core.spi.transaction.ConnectableResource;
import org.ironjacamar.core.spi.transaction.TxUtils;
import org.ironjacamar.core.spi.transaction.local.LocalXAResource;
Expand Down Expand Up @@ -89,6 +91,10 @@ public abstract class AbstractPool implements Pool

private FlushStrategy flushStrategy;

/** The capacity */
private Capacity capacity;


/**
* Constructor
*
Expand All @@ -103,6 +109,7 @@ public AbstractPool(ConnectionManager cm, PoolConfiguration pc)
this.transactionMap = new ConcurrentHashMap<Object, Map<ManagedConnectionPool, ConnectionListener>>();
this.semaphore = new Semaphore(poolConfiguration.getMaxSize());
this.flushStrategy = poolConfiguration.getFlushStrategy();
this.capacity = null;
}

/**
Expand Down Expand Up @@ -817,4 +824,36 @@ public ConnectionListener getActiveConnectionListener(Credential credential)

return null;
}

/**
* {@inheritDoc}
*/
public Capacity getCapacity()
{
if (capacity == null)
return DefaultCapacity.INSTANCE;

return capacity;
}

/**
* {@inheritDoc}
*/
public void setCapacity(Capacity c)
{
capacity = c;
}


/**
* {@inheritDoc}
*/
public boolean isFIFO()
{
if (capacity == null || capacity.getDecrementer() == null ||
TimedOutDecrementer.class.getName().equals(capacity.getDecrementer().getClass().getName()))
return false;

return true;
}
}
@@ -0,0 +1,44 @@
/*
* 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.connectionmanager.pool;

import org.ironjacamar.core.api.connectionmanager.pool.CapacityDecrementer;
import org.ironjacamar.core.api.connectionmanager.pool.CapacityIncrementer;

/**
* The capacity policy
*
* @author <a href="mailto:jesper.pedersen@ironjacamar.org">Jesper Pedersen</a>
*/
public interface Capacity
{
/**
* Get the incrementer policy
* @return The policy; can be <code>null</code> for container default policy
*/
public CapacityIncrementer getIncrementer();

/**
* Get the decrementer policy
* @return The policy; can be <code>null</code> for container default policy
*/
public CapacityDecrementer getDecrementer();
}

0 comments on commit ab1d3b9

Please sign in to comment.