All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.jca.HazelcastConnectionImpl Maven / Gradle / Ivy

There is a newer version: 3.7.2
Show newest version
/*
 * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed 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 com.hazelcast.jca;

import com.hazelcast.config.Config;
import com.hazelcast.core.ClientService;
import com.hazelcast.core.Cluster;
import com.hazelcast.core.DistributedObject;
import com.hazelcast.core.DistributedObjectListener;
import com.hazelcast.core.Endpoint;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IAtomicLong;
import com.hazelcast.core.IAtomicReference;
import com.hazelcast.core.ICountDownLatch;
import com.hazelcast.core.IExecutorService;
import com.hazelcast.core.IList;
import com.hazelcast.core.ILock;
import com.hazelcast.core.IMap;
import com.hazelcast.core.IQueue;
import com.hazelcast.core.ISemaphore;
import com.hazelcast.core.ISet;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.IdGenerator;
import com.hazelcast.core.LifecycleService;
import com.hazelcast.core.MultiMap;
import com.hazelcast.core.PartitionService;
import com.hazelcast.core.ReplicatedMap;
import com.hazelcast.core.TransactionalList;
import com.hazelcast.core.TransactionalMap;
import com.hazelcast.core.TransactionalMultiMap;
import com.hazelcast.core.TransactionalQueue;
import com.hazelcast.core.TransactionalSet;
import com.hazelcast.logging.LoggingService;
import com.hazelcast.mapreduce.JobTracker;
import com.hazelcast.quorum.QuorumService;
import com.hazelcast.ringbuffer.Ringbuffer;
import com.hazelcast.transaction.HazelcastXAResource;
import com.hazelcast.transaction.TransactionContext;
import com.hazelcast.transaction.TransactionException;
import com.hazelcast.transaction.TransactionOptions;
import com.hazelcast.transaction.TransactionalTask;
import com.hazelcast.util.ExceptionUtil;

import javax.resource.NotSupportedException;
import javax.resource.ResourceException;
import javax.resource.cci.ConnectionMetaData;
import javax.resource.cci.Interaction;
import javax.resource.cci.ResultSetInfo;
import javax.resource.spi.ConnectionEvent;
import javax.security.auth.Subject;
import java.util.Collection;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;

/**
 * Implementation class of {@link com.hazelcast.jca.HazelcastConnectionImpl}
 */
public class HazelcastConnectionImpl implements HazelcastConnection {
    /**
     * Identity generator
     */
    private static AtomicInteger idGen = new AtomicInteger();
    /**
     * Reference to this creator and access to container infrastructure
     */
    final ManagedConnectionImpl managedConnection;
    /**
     * this identity
     */
    private final int id;

    public HazelcastConnectionImpl(ManagedConnectionImpl managedConnectionImpl, Subject subject) {
        this.managedConnection = managedConnectionImpl;
        id = idGen.incrementAndGet();
    }

    @Override
    public void close() throws ResourceException {
        managedConnection.log(Level.FINEST, "close");
        //important: inform the container!
        managedConnection.fireConnectionEvent(ConnectionEvent.CONNECTION_CLOSED, this);
    }

    @Override
    public Interaction createInteraction() throws ResourceException {
        //TODO
        return null;
    }

    /**
     * @throws NotSupportedException as this is not supported by this resource adapter
     */
    @Override
    public ResultSetInfo getResultSetInfo() throws NotSupportedException {
        throw new NotSupportedException("getResultSetInfo() is not supported by this resource adapter as per spec 15.11.3");
    }

    @Override
    public HazelcastTransaction getLocalTransaction() throws ResourceException {
        managedConnection.log(Level.FINEST, "getLocalTransaction");
        return managedConnection.getLocalTransaction();
    }

    @Override
    public ConnectionMetaData getMetaData() throws ResourceException {
        return managedConnection.getMetaData();
    }

    @Override
    public String toString() {
        return "hazelcast.ConnectionImpl [" + id + "]";
    }

    /**
     * Method is not exposed to force all clients to go through this connection object and its
     * methods from {@link HazelcastConnection}
     *
     * @return the local hazelcast instance
     */
    private HazelcastInstance getHazelcastInstance() {
        return managedConnection.getHazelcastInstance();
    }

    @Override
    public  IMap getMap(String name) {
        return getHazelcastInstance().getMap(name);
    }

    @Override
    public  IQueue getQueue(String name) {
        return getHazelcastInstance().getQueue(name);
    }

    @Override
    public  ITopic getTopic(String name) {
        return getHazelcastInstance().getTopic(name);
    }

    @Override
    public  ITopic getReliableTopic(String name) {
        return getHazelcastInstance().getReliableTopic(name);
    }

    @Override
    public  ISet getSet(String name) {
        return getHazelcastInstance().getSet(name);
    }

    @Override
    public  IList getList(String name) {
        return getHazelcastInstance().getList(name);
    }

    @Override
    public  MultiMap getMultiMap(String name) {
        return getHazelcastInstance().getMultiMap(name);
    }

    @Override
    public IExecutorService getExecutorService(String name) {
        return getHazelcastInstance().getExecutorService(name);
    }

    @Override
    public IAtomicLong getAtomicLong(String name) {
        return getHazelcastInstance().getAtomicLong(name);
    }

    @Override
    public ICountDownLatch getCountDownLatch(String name) {
        return getHazelcastInstance().getCountDownLatch(name);
    }

    @Override
    public ISemaphore getSemaphore(String name) {
        return getHazelcastInstance().getSemaphore(name);
    }

    @Override
    public Collection getDistributedObjects() {
        return getHazelcastInstance().getDistributedObjects();
    }

    @Override
    public String addDistributedObjectListener(DistributedObjectListener distributedObjectListener) {
        return getHazelcastInstance().addDistributedObjectListener(distributedObjectListener);
    }

    @Override
    public boolean removeDistributedObjectListener(String registrationId) {
        return getHazelcastInstance().removeDistributedObjectListener(registrationId);
    }

    @Override
    public Config getConfig() {
        return getHazelcastInstance().getConfig();
    }

    @Override
    public PartitionService getPartitionService() {
        return getHazelcastInstance().getPartitionService();
    }

    @Override
    public QuorumService getQuorumService() {
        return getHazelcastInstance().getQuorumService();
    }

    @Override
    public ClientService getClientService() {
        return getHazelcastInstance().getClientService();
    }

    @Override
    public LoggingService getLoggingService() {
        return getHazelcastInstance().getLoggingService();
    }

    @Override
    public  T getDistributedObject(String serviceName, String name) {
        return getHazelcastInstance().getDistributedObject(serviceName, name);
    }

    @Override
    public ConcurrentMap getUserContext() {
        return getHazelcastInstance().getUserContext();
    }

    @Override
    public  TransactionalMap getTransactionalMap(String name) {
        TransactionContext txContext = getTransactionContext();
        return txContext.getMap(name);
    }

    @Override
    public  TransactionalQueue getTransactionalQueue(String name) {
        TransactionContext txContext = getTransactionContext();
        return txContext.getQueue(name);
    }

    @Override
    public  TransactionalMultiMap getTransactionalMultiMap(String name) {
        TransactionContext txContext = getTransactionContext();
        return txContext.getMultiMap(name);
    }

    @Override
    public  TransactionalList getTransactionalList(String name) {
        TransactionContext txContext = getTransactionContext();
        return txContext.getList(name);
    }

    @Override
    public  TransactionalSet getTransactionalSet(String name) {
        TransactionContext txContext = getTransactionContext();
        return txContext.getSet(name);
    }

    private TransactionContext getTransactionContext() {
        TransactionContext transactionContext = managedConnection.getTransactionContext();
        if (transactionContext != null) {
            return transactionContext;
        }
        HazelcastXAResource xaResource = getXAResource();
        return xaResource.getTransactionContext();
    }

    @Override
    public IdGenerator getIdGenerator(String name) {
        return getHazelcastInstance().getIdGenerator(name);
    }

    @Override
    public  IAtomicReference getAtomicReference(String name) {
        return getHazelcastInstance().getAtomicReference(name);
    }

    @Override
    public  ReplicatedMap getReplicatedMap(String name) {
        return getHazelcastInstance().getReplicatedMap(name);
    }

    @Override
    public  Ringbuffer getRingbuffer(String name) {
        return getHazelcastInstance().getRingbuffer(name);
    }

    @Override
    public JobTracker getJobTracker(String name) {
        return getHazelcastInstance().getJobTracker(name);
    }

    @Override
    public String getName() {
        return getHazelcastInstance().getName();
    }


    @Override
    public ILock getLock(String key) {
        return getHazelcastInstance().getLock(key);
    }

    @Override
    public Cluster getCluster() {
        return getHazelcastInstance().getCluster();
    }

    @Override
    public Endpoint getLocalEndpoint() {
        return getHazelcastInstance().getLocalEndpoint();
    }

    @Override
    public HazelcastXAResource getXAResource() {
        try {
            return (HazelcastXAResource) managedConnection.getXAResource();
        } catch (ResourceException e) {
            throw ExceptionUtil.rethrow(e);
        }
    }

    // unsupported operations

    @Override
    public LifecycleService getLifecycleService() {
        throw new UnsupportedOperationException("Hazelcast Lifecycle is only managed by JCA Container");
    }

    @Override
    public void shutdown() {
        throw new UnsupportedOperationException("Hazelcast Lifecycle is only managed by JCA Container");
    }

    @Override
    public  T executeTransaction(TransactionalTask task) throws TransactionException {
        throw new UnsupportedOperationException("getTransactional*() methods are "
                + "only methods allowed for transactional operations!");
    }

    @Override
    public  T executeTransaction(TransactionOptions options, TransactionalTask task) throws TransactionException {
        throw new UnsupportedOperationException("getTransactional*() methods are "
                + "only methods allowed for transactional operations!");
    }

    @Override
    public TransactionContext newTransactionContext() {
        throw new UnsupportedOperationException("getTransactional*() methods are "
                + "only methods allowed for transactional operations!");
    }

    @Override
    public TransactionContext newTransactionContext(TransactionOptions options) {
        throw new UnsupportedOperationException("getTransactional*() methods are "
                + "only methods allowed for transactional operations!");
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy