Search in sources :

Example 1 with LifecycleAware

use of org.apache.ignite.lifecycle.LifecycleAware in project ignite by apache.

the class HadoopBasicFileSystemFactoryDelegate method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteException {
    BasicHadoopFileSystemFactory proxy0 = (BasicHadoopFileSystemFactory) proxy;
    cfg = HadoopUtils.safeCreateConfiguration();
    if (proxy0.getConfigPaths() != null) {
        for (String cfgPath : proxy0.getConfigPaths()) {
            if (cfgPath == null)
                throw new NullPointerException("Configuration path cannot be null: " + Arrays.toString(proxy0.getConfigPaths()));
            else {
                URL url = U.resolveIgniteUrl(cfgPath);
                if (url == null) {
                    // If secConfPath is given, it should be resolvable:
                    throw new IgniteException("Failed to resolve secondary file system configuration path " + "(ensure that it exists locally and you have read access to it): " + cfgPath);
                }
                cfg.addResource(url);
            }
        }
    }
    // If secondary fs URI is not given explicitly, try to get it from the configuration:
    if (proxy0.getUri() == null)
        fullUri = FileSystem.getDefaultUri(cfg);
    else {
        try {
            fullUri = new URI(proxy0.getUri());
        } catch (URISyntaxException ignored) {
            throw new IgniteException("Failed to resolve secondary file system URI: " + proxy0.getUri());
        }
    }
    String strWorkDir = fullUri.getPath();
    if (!"/".equals(strWorkDir))
        workDir = new Path(strWorkDir);
    usrNameMapper = proxy0.getUserNameMapper();
    if (usrNameMapper != null && usrNameMapper instanceof LifecycleAware)
        ((LifecycleAware) usrNameMapper).start();
}
Also used : Path(org.apache.hadoop.fs.Path) LifecycleAware(org.apache.ignite.lifecycle.LifecycleAware) IgniteException(org.apache.ignite.IgniteException) BasicHadoopFileSystemFactory(org.apache.ignite.hadoop.fs.BasicHadoopFileSystemFactory) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL)

Example 2 with LifecycleAware

use of org.apache.ignite.lifecycle.LifecycleAware in project ignite by apache.

the class CacheJtaManager method start0.

/**
 * {@inheritDoc}
 */
@Override
protected void start0() throws IgniteCheckedException {
    super.start0();
    if (cctx.txConfig() != null) {
        tmFactory = cctx.txConfig().getTxManagerFactory();
        if (tmFactory != null) {
            cctx.kernalContext().resource().injectGeneric(tmFactory);
            if (tmFactory instanceof LifecycleAware)
                ((LifecycleAware) tmFactory).start();
            Object txMgr;
            try {
                txMgr = tmFactory.create();
            } catch (Exception e) {
                throw new IgniteCheckedException("Failed to create transaction manager [tmFactory=" + tmFactory + "]", e);
            }
            if (txMgr == null)
                throw new IgniteCheckedException("Failed to create transaction manager (transaction manager " + "factory created null-value transaction manager) [tmFactory=" + tmFactory + "]");
            if (!(txMgr instanceof TransactionManager))
                throw new IgniteCheckedException("Failed to create transaction manager (transaction manager " + "factory created object that is not an instance of TransactionManager) [tmFactory=" + tmFactory + ", txMgr=" + txMgr + "]");
            jtaTm = (TransactionManager) txMgr;
        } else {
            String txLookupClsName = cctx.txConfig().getTxManagerLookupClassName();
            if (txLookupClsName != null)
                tmLookupRef.set(createTmLookup(txLookupClsName));
        }
        useJtaSync = cctx.txConfig().isUseJtaSynchronization();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LifecycleAware(org.apache.ignite.lifecycle.LifecycleAware) TransactionManager(javax.transaction.TransactionManager) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 3 with LifecycleAware

use of org.apache.ignite.lifecycle.LifecycleAware in project ignite by apache.

the class CacheJtaManager method createTmLookup.

/**
 * @throws IgniteCheckedException
 */
private CacheTmLookup createTmLookup(String tmLookupClsName) throws IgniteCheckedException {
    try {
        Class<?> cls = Class.forName(tmLookupClsName);
        CacheTmLookup res = (CacheTmLookup) cls.newInstance();
        cctx.kernalContext().resource().injectGeneric(res);
        if (res instanceof LifecycleAware)
            ((LifecycleAware) res).start();
        return res;
    } catch (Exception e) {
        throw new IgniteCheckedException("Failed to instantiate transaction manager lookup.", e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LifecycleAware(org.apache.ignite.lifecycle.LifecycleAware) CacheTmLookup(org.apache.ignite.cache.jta.CacheTmLookup) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 4 with LifecycleAware

use of org.apache.ignite.lifecycle.LifecycleAware in project ignite by apache.

the class GridCacheUtils method startStoreSessionListeners.

/**
 * Creates and starts store session listeners.
 *
 * @param ctx Kernal context.
 * @param factories Factories.
 * @return Listeners.
 * @throws IgniteCheckedException In case of error.
 */
public static Collection<CacheStoreSessionListener> startStoreSessionListeners(GridKernalContext ctx, Factory<CacheStoreSessionListener>[] factories) throws IgniteCheckedException {
    if (factories == null)
        return null;
    Collection<CacheStoreSessionListener> lsnrs = new ArrayList<>(factories.length);
    for (Factory<CacheStoreSessionListener> factory : factories) {
        CacheStoreSessionListener lsnr = factory.create();
        if (lsnr != null) {
            ctx.resource().injectGeneric(lsnr);
            if (lsnr instanceof LifecycleAware)
                ((LifecycleAware) lsnr).start();
            lsnrs.add(lsnr);
        }
    }
    return lsnrs;
}
Also used : LifecycleAware(org.apache.ignite.lifecycle.LifecycleAware) ArrayList(java.util.ArrayList) CacheStoreSessionListener(org.apache.ignite.cache.store.CacheStoreSessionListener)

Example 5 with LifecycleAware

use of org.apache.ignite.lifecycle.LifecycleAware in project ignite by apache.

the class GridCacheStoreManagerAdapter method start0.

/**
 * {@inheritDoc}
 */
@Override
protected void start0() throws IgniteCheckedException {
    if (store instanceof LifecycleAware) {
        try {
            // Avoid second start() call on store in case when near cache is enabled.
            if (cctx.config().isWriteBehindEnabled()) {
                if (!cctx.isNear())
                    ((LifecycleAware) store).start();
            }
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to start cache store: " + e, e);
        }
    }
    CacheConfiguration cfg = cctx.config();
    if (cfgStore != null) {
        if (!cfg.isWriteThrough() && !cfg.isReadThrough()) {
            U.quietAndWarn(log, "Persistence store is configured, but both read-through and write-through are disabled. This " + "configuration makes sense if the store implements loadCache method only. If this is the " + "case, ignore this warning. Otherwise, fix the configuration for the cache: " + cfg.getName(), "Persistence store is configured, but both read-through and write-through are disabled " + "for cache: " + cfg.getName());
        }
        if (!cfg.isWriteThrough() && cfg.isWriteBehindEnabled()) {
            U.quietAndWarn(log, "To enable write-behind mode for the cache store it's also required to set " + "CacheConfiguration.setWriteThrough(true) property, otherwise the persistence " + "store will be never updated. Consider fixing configuration for the cache: " + cfg.getName(), "Write-behind mode for the cache store also requires CacheConfiguration.setWriteThrough(true) " + "property. Fix configuration for the cache: " + cfg.getName());
        }
        if (cctx.group().persistenceEnabled() && (cfg.isWriteThrough() || cfg.isReadThrough()))
            U.quietAndWarn(log, "Both Ignite native persistence and CacheStore are configured for cache '" + cfg.getName() + "'. " + "This configuration does not guarantee strict consistency between CacheStore and Ignite data " + "storage upon restarts. Consult documentation for more details.");
    }
    sesLsnrs = CU.startStoreSessionListeners(cctx.kernalContext(), cfg.getCacheStoreSessionListenerFactories());
    if (sesLsnrs == null) {
        sesLsnrs = cctx.shared().storeSessionListeners();
        globalSesLsnrs = true;
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LifecycleAware(org.apache.ignite.lifecycle.LifecycleAware) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheWriterException(javax.cache.integration.CacheWriterException) CacheLoaderException(javax.cache.integration.CacheLoaderException) NoSuchElementException(java.util.NoSuchElementException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

LifecycleAware (org.apache.ignite.lifecycle.LifecycleAware)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 RollbackException (javax.transaction.RollbackException)2 SystemException (javax.transaction.SystemException)2 IgniteException (org.apache.ignite.IgniteException)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 CacheLoaderException (javax.cache.integration.CacheLoaderException)1 CacheWriterException (javax.cache.integration.CacheWriterException)1 TransactionManager (javax.transaction.TransactionManager)1 Path (org.apache.hadoop.fs.Path)1 CacheTmLookup (org.apache.ignite.cache.jta.CacheTmLookup)1 CacheStoreSessionListener (org.apache.ignite.cache.store.CacheStoreSessionListener)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 BasicHadoopFileSystemFactory (org.apache.ignite.hadoop.fs.BasicHadoopFileSystemFactory)1 CacheStorePartialUpdateException (org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException)1