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

org.ehcache.transactions.xa.txmgr.provider.LookupTransactionManagerProvider Maven / Gradle / Ivy

There is a newer version: 3.10.8
Show newest version
/*
 * Copyright Terracotta, Inc.
 *
 * 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 org.ehcache.transactions.xa.txmgr.provider;

import org.ehcache.spi.service.ServiceProvider;
import org.ehcache.spi.service.Service;
import org.ehcache.spi.service.ServiceDependencies;
import org.ehcache.transactions.xa.internal.XAStore;
import org.ehcache.transactions.xa.txmgr.TransactionManagerWrapper;

/**
 * A {@link TransactionManagerProvider} implementation that resolves the {@link TransactionManagerWrapper} through the
 * {@link TransactionManagerLookup lookup class} provided through its {@link LookupTransactionManagerProviderConfiguration}.
 * 

* The lifecycle this implementation will honour is as follows: *

    *
  • On construction, instantiate the lookup class indicated by configuration
  • *
  • On {@code start} the service will ask the lookup instance for a {@code TransactionManagerWrapper} * which it will then cache and serve to service users.
  • *
  • On {@code stop} the service will forget about the known {@code TransactionManagerWrapper}
  • *
  • On subsequent {@code start}, the service will ask the lookup instance for a new * {@code TransactionManagerWrapper}
  • *
* Note that in this scheme, the lookup instance is not expected to cache the {@code TransactionManagerWrapper} * unless it can be considered a singleton. *

*/ public class LookupTransactionManagerProvider implements TransactionManagerProvider { private final TransactionManagerLookup lookup; private volatile TransactionManagerWrapper transactionManagerWrapper; /** * Creates a new instance with the provided configuration. * * @param config the service creation configuration * * @throws NullPointerException if the config is {@code null} */ public LookupTransactionManagerProvider(LookupTransactionManagerProviderConfiguration config) { if (config == null) { throw new NullPointerException("LookupTransactionManagerProviderConfiguration cannot be null"); } try { lookup = config.getTransactionManagerLookup().newInstance(); } catch (InstantiationException e) { throw new IllegalArgumentException("Could not instantiate lookup class", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Could not instantiate lookup class", e); } } /** * {@inheritDoc} */ @Override public TransactionManagerWrapper getTransactionManagerWrapper() { return transactionManagerWrapper; } /** * {@inheritDoc} */ @Override public void start(ServiceProvider serviceProvider) { this.transactionManagerWrapper = lookup.lookupTransactionManagerWrapper(); } /** * {@inheritDoc} */ @Override public void stop() { this.transactionManagerWrapper = null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy