use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class BasicResourceAllocator method createResource.
public ResourceHandle createResource(XAResource xaResource) throws PoolingException {
ResourceHandle resourceHandle = null;
ResourceSpec spec = new ResourceSpec(JMS_RESOURCE_FACTORY, ResourceSpec.JMS);
if (xaResource != null) {
logger.logp(Level.FINEST, "BasicResourceAllocator", "createResource", "NOT NULL", xaResource);
try {
resourceHandle = new ResourceHandle(// no object present
null, spec, this, null);
if (logger.isLoggable(Level.FINEST)) {
xaResource = new XAResourceWrapper(xaResource);
}
resourceHandle.fillInResourceObjects(null, xaResource);
} catch (Exception e) {
throw (PoolingException) (new PoolingException()).initCause(e);
}
} else {
logger.logp(Level.FINEST, "BasicResourceAllocator", "createResource", "NULL");
}
return resourceHandle;
}
use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class ConnectorMessageBeanClient method createEndpoint.
/**
* {@inheritDoc}
*/
public MessageEndpoint createEndpoint(XAResource xaResource, long timeout) throws UnavailableException {
synchronized (this) {
while (myState == BLOCKED) {
try {
wait(timeout);
} catch (Exception e) {
// This exception should not affect the functionality.
} finally {
// Once the first thread comes out of wait, block is
// is removed. This makes sure that the time for which the
// the block remains is limited. Max 2x6000.
myState = UNBLOCKED;
}
}
}
if (!started_) {
logger.log(Level.WARNING, "endpointfactory.unavailable");
throw new UnavailableException("EndpointFactory is currently not available");
}
MessageEndpoint endpoint = null;
try {
ResourceHandle resourceHandle = allocator_.createResource(xaResource);
MessageBeanListener listener = messageBeanPM_.createMessageBeanListener(resourceHandle);
MessageEndpointInvocationHandler handler = new MessageEndpointInvocationHandler(listener, messageBeanPM_);
endpoint = (MessageEndpoint) messageBeanPM_.createMessageBeanProxy(handler);
} catch (Exception ex) {
throw (UnavailableException) (new UnavailableException()).initCause(ex);
}
return endpoint;
}
use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class AssocWithThreadResourcePool method getUnenlistedResource.
// this is the RI getResource() with some modifications
/**
* return resource in free list. If none is found, returns null
*/
protected ResourceHandle getUnenlistedResource(ResourceSpec spec, ResourceAllocator alloc, Transaction tran) throws PoolingException {
ResourceHandle result;
result = super.getUnenlistedResource(spec, alloc, tran);
// and hence we should not use this resource.
if (result != null) {
synchronized (result.lock) {
if (ds.getAllResources().contains(result) && ((AssocWithThreadResourceHandle) result).isDirty()) {
// Remove the resource and set to null
ds.removeResource(result);
result = null;
}
}
}
// DISASSOCIATE
if (result == null) {
synchronized (this) {
for (ResourceHandle resource : ds.getAllResources()) {
synchronized (resource.lock) {
if (resource.getResourceState().isUnenlisted() && resource.getResourceState().isFree() && !(((AssocWithThreadResourceHandle) resource).isDirty())) {
if (!matchConnection(resource, alloc)) {
continue;
}
if (resource.hasConnectionErrorOccurred()) {
continue;
}
result = resource;
setResourceStateToBusy(result);
((AssocWithThreadResourceHandle) result).setAssociated(false);
break;
}
}
}
}
}
if (localResource.get() == null) {
setInThreadLocal((AssocWithThreadResourceHandle) result);
}
return result;
}
use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class ListDataStructure method addResource.
/**
* creates a new resource and adds to the datastructure.
*
* @param allocator ResourceAllocator
* @param count Number (units) of resources to create
* @return int number of resources added
*/
public int addResource(ResourceAllocator allocator, int count) throws PoolingException {
int numResAdded = 0;
for (int i = 0; i < count && resources.size() < maxSize; i++) {
boolean lockAcquired = dynSemaphore.tryAcquire();
if (lockAcquired) {
try {
ResourceHandle handle = handler.createResource(allocator);
synchronized (resources) {
synchronized (free) {
free.add(handle);
resources.add(handle);
numResAdded++;
}
}
} catch (Exception e) {
dynSemaphore.release();
PoolingException pe = new PoolingException(e.getMessage());
pe.initCause(e);
throw pe;
}
}
}
return numResAdded;
}
use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class ListDataStructure method removeAll.
/**
* remove & destroy all resources from the datastructure.
*/
public void removeAll() {
synchronized (resources) {
synchronized (free) {
while (resources.size() > 0) {
ResourceHandle handle = resources.remove(0);
free.remove(handle);
dynSemaphore.release();
handler.deleteResource(handle);
}
}
}
free.clear();
resources.clear();
}
Aggregations