Package com.hazelcast.core

Examples of com.hazelcast.core.Transaction


            Composite dc = ((RuntimeEndpoint)endpoint).getCompositeContext().getDomainComposite();
            if (dc != null) {
                curi = dc.getContributionURI();
            }
        }
        Transaction txn = hazelcastInstance.getTransaction();
        txn.begin();
        try {
            localEndpoints.put(endpointURI, endpoint);
            endpointMap.put(endpointURI, endpoint);
            endpointOwners.put(localMemberAddr, endpointURI);
            if (curi != null) {
                runningComponentContributions.put(componentName, curi);
            }
            txn.commit();
        } catch (Throwable e) {
            txn.rollback();
            throw new ServiceRuntimeException(e);
        }
        logger.info("Add endpoint - " + endpoint);
    }
View Full Code Here


        }
        synchronized (shutdownMutex) {
            String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
            String endpointURI = endpoint.getURI();
            String componentName = endpoint.getComponent().getName();
            Transaction txn = hazelcastInstance.getTransaction();
            txn.begin();
            try {
                endpointOwners.remove(localMemberAddr, endpointURI);
                endpointMap.remove(endpointURI);
                runningComponentContributions.remove(componentName);
                txn.commit();
            } catch (Throwable e) {
                txn.rollback();
                throw new ServiceRuntimeException(e);
            }
            localEndpoints.remove(endpointURI);
            logger.info("Removed endpoint - " + endpoint);
        }
View Full Code Here

    }

    public void addRunningComposite(String curi, Composite composite) {
        String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
        String compositeXML = writeComposite(composite);
        Transaction txn = hazelcastInstance.getTransaction();
        txn.begin();
        try {
            Map<String, String> cs = runningComposites.get(curi);
            if (cs == null) {
                cs = new HashMap<String, String>();
            }
            cs.put(composite.getURI(), compositeXML);
            runningComposites.put(curi, cs);
            Map<String, List<String>> ocs = runningCompositeOwners.get(localMemberAddr);
            if (ocs == null) {
                ocs = new HashMap<String, List<String>>();
            }
            List<String> lcs = ocs.get(curi);
            if (lcs == null) {
                lcs = new ArrayList<String>();
                ocs.put(curi, lcs);
            }
            lcs.add(composite.getURI());
            runningCompositeOwners.put(localMemberAddr, ocs);
            txn.commit();
        } catch (Throwable e) {
            txn.rollback();
            throw new ServiceRuntimeException(e);
        }
    }
View Full Code Here

        }
    }

    public void removeRunningComposite(String curi, String compositeURI) {
        String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
        Transaction txn = hazelcastInstance.getTransaction();
        txn.begin();
        try {
            Map<String, String> cs = runningComposites.get(curi);
            if (cs != null) {
                cs.remove(compositeURI);
                if (cs.size() > 0) {
                    runningComposites.put(curi, cs);               
                } else {
                    runningComposites.remove(curi);               
                }
            }
            Map<String, List<String>> ocs = runningCompositeOwners.get(localMemberAddr);
            if (ocs != null) {
                List<String> xya = ocs.get(curi);
                if (xya != null) {
                    xya.remove(compositeURI);
                    if (xya.size() > 0) {
                        runningCompositeOwners.put(localMemberAddr, ocs);
                    } else {
                        runningCompositeOwners.remove(localMemberAddr);
                    }
                }
            }
            txn.commit();
        } catch (Throwable e) {
            txn.rollback();
            throw new ServiceRuntimeException(e);
        }
    }
View Full Code Here

            throw new IllegalStateException("Endpoint " + endpoint.getURI() + " already exists in domain " + domainURI + " at " + m.getInetSocketAddress());
        }
           
        String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
        String endpointURI = endpoint.getURI();
        Transaction txn = hazelcastInstance.getTransaction();
        txn.begin();
        try {
            endpointMap.put(endpointURI, endpoint);
            endpointOwners.put(localMemberAddr, endpointURI);
            txn.commit();
        } catch (Throwable e) {
            txn.rollback();
            throw new ServiceRuntimeException(e);
        }
        localEndpoints.put(endpointURI, endpoint);
        logger.info("Add endpoint - " + endpoint);
    }
View Full Code Here

            Composite dc = ((RuntimeEndpoint)endpoint).getCompositeContext().getDomainComposite();
            if (dc != null) {
                curi = dc.getContributionURI();
            }
        }
        Transaction txn = hazelcastInstance.getTransaction();
        txn.begin();
        try {
            localEndpoints.put(endpointURI, endpoint);
            endpointMap.put(endpointURI, endpoint);
            endpointOwners.put(localMemberAddr, endpointURI);
            if (curi != null) {
                runningComponentContributions.put(componentName, curi);
            }
            txn.commit();
        } catch (Throwable e) {
            txn.rollback();
            throw new ServiceRuntimeException(e);
        }
        logger.info("Add endpoint - " + endpoint);
    }
View Full Code Here

        }
        synchronized (shutdownMutex) {
            String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
            String endpointURI = endpoint.getURI();
            String componentName = endpoint.getComponent().getName();
            Transaction txn = hazelcastInstance.getTransaction();
            txn.begin();
            try {
                endpointOwners.remove(localMemberAddr, endpointURI);
                endpointMap.remove(endpointURI);
                runningComponentContributions.remove(componentName);
                txn.commit();
            } catch (Throwable e) {
                txn.rollback();
                throw new ServiceRuntimeException(e);
            }
            localEndpoints.remove(endpointURI);
            logger.info("Removed endpoint - " + endpoint);
        }
View Full Code Here

    }

    public void addRunningComposite(String curi, Composite composite) {
        String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
        String compositeXML = writeComposite(composite);
        Transaction txn = hazelcastInstance.getTransaction();
        txn.begin();
        try {
            Map<String, String> cs = runningComposites.get(curi);
            if (cs == null) {
                cs = new HashMap<String, String>();
            }
            cs.put(composite.getURI(), compositeXML);
            runningComposites.put(curi, cs);
            Map<String, List<String>> ocs = runningCompositeOwners.get(localMemberAddr);
            if (ocs == null) {
                ocs = new HashMap<String, List<String>>();
            }
            List<String> lcs = ocs.get(curi);
            if (lcs == null) {
                lcs = new ArrayList<String>();
                ocs.put(curi, lcs);
            }
            lcs.add(composite.getURI());
            runningCompositeOwners.put(localMemberAddr, ocs);
            txn.commit();
        } catch (Throwable e) {
            txn.rollback();
            throw new ServiceRuntimeException(e);
        }
    }
View Full Code Here

        }
    }

    public void removeRunningComposite(String curi, String compositeURI) {
        String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
        Transaction txn = hazelcastInstance.getTransaction();
        txn.begin();
        try {
            Map<String, String> cs = runningComposites.get(curi);
            if (cs != null) {
                cs.remove(compositeURI);
                if (cs.size() > 0) {
                    runningComposites.put(curi, cs);               
                } else {
                    runningComposites.remove(curi);               
                }
            }
            Map<String, List<String>> ocs = runningCompositeOwners.get(localMemberAddr);
            if (ocs != null) {
                List<String> xya = ocs.get(curi);
                if (xya != null) {
                    xya.remove(compositeURI);
                    if (xya.size() > 0) {
                        runningCompositeOwners.put(localMemberAddr, ocs);
                    } else {
                        runningCompositeOwners.remove(localMemberAddr);
                    }
                }
            }
            txn.commit();
        } catch (Throwable e) {
            txn.rollback();
            throw new ServiceRuntimeException(e);
        }
    }
View Full Code Here

        final BlockingQueue<?> queue = endpoint.getQueue();

        while (queue != null && isRunAllowed()) {
            final Exchange exchange = this.getEndpoint().createExchange();

            Transaction transaction = null;
            if (endpoint.getConfiguration().isTransacted()) {
                // Get and begin transaction if exist
                transaction = endpoint.getHazelcastInstance().getTransaction();

                if (transaction != null && transaction.getStatus() == Transaction.TXN_STATUS_NO_TXN) {
                    log.trace("Begin transaction: {}", transaction);
                    transaction.begin();
                }
            }
            try {
                final Object body = queue.poll(endpoint.getConfiguration().getPollInterval(), TimeUnit.MILLISECONDS);

                if (body != null) {
                    if (body instanceof DefaultExchangeHolder) {
                        DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) body);
                    } else {
                        exchange.getIn().setBody(body);
                    }
                    try {
                        // process using the asynchronous routing engine
                        processor.process(exchange, new AsyncCallback() {
                            public void done(boolean asyncDone) {
                                // noop
                            }
                        });

                        if (exchange.getException() != null) {
                            // Rollback
                            if (transaction != null) {
                                transaction.rollback();
                            }
                            getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
                        }

                    } catch (Exception e) {
                        LOG.error("Hzlq Exception caught: " + e, e);
                        // Rollback
                        if (transaction != null) {
                            log.trace("Rollback transaction: {}", transaction);
                            transaction.rollback();
                        }
                    }
                }
                // It's OK, I commit
                if (exchange.getException() == null && transaction != null && transaction.getStatus() == Transaction.TXN_STATUS_ACTIVE) {
                    log.trace("Commit transaction: {}", transaction);
                    transaction.commit();
                }
            } catch (InterruptedException e) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Hzlq Consumer Interrupted: " + e, e);
                }
                continue;
            } catch (Throwable e) {
                // Rollback
                if (transaction != null) {
                    log.trace("Rollback transaction: {}", transaction);
                    transaction.rollback();
                }
                getExceptionHandler().handleException("Error processing exchange", exchange, e);
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.