Package com.arjuna.wst11.tests.junit.ba

Examples of com.arjuna.wst11.tests.junit.ba.Close


    @WebMethod
    public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {

        System.out.println("[SERVICE] invoked addValueToSet('" + value + "')");

        BAParticipantManager participantManager;

        try {
            // enlist the Participant for this service:
            SetParticipantBA participant = new SetParticipantBA(value);
            BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
            System.out.println("[SERVICE] Enlisting a participant into the BA");
            participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(participant,
                    "SetServiceBAImpl:" + UUID.randomUUID());
        } catch (Exception e) {
            System.err.println("Participant enlistment failed");
            e.printStackTrace(System.err);
            throw new SetServiceException("Error enlisting participant", e);
        }

        // invoke the back-end business logic
        System.out.println("[SERVICE] Invoking the back-end business logic");
        MockSetManager.add(value);

        /*
         * this service employs the participant completion protocol which means it decides when it wants to commit local
         * changes. If the local changes (adding the item to the set) succeeded, we notify the coordinator that we have
         * completed. Otherwise, we notify the coordinator that we cannot complete. If any other participant fails or the client
         * decides to cancel we can rely upon being told to compensate.
         */
        System.out
                .println("[SERVICE] Prepare the backend resource and if successful notify the coordinator that we have completed our work");
        if (MockSetManager.prepare()) {
            try {
                // tell the coordinator manager we have finished our work
                System.out.println("[SERVICE] Prepare successful, notifying coordinator of completion");
                participantManager.completed();
            } catch (Exception e) {
                /*
                 * Failed to notify the coordinator that we have finished our work. Compensate the work and throw an Exception
                 * to notify the client that the add operation failed.
                 */
                MockSetManager.rollback(value);

                System.err.println("[SERVICE]  'completed' callback failed");
                throw new SetServiceException("Error when notifying the coordinator that the work is completed", e);
            }
        } else {
            try {
                /*
                 * tell the participant manager we cannot complete. this will force the activity to fail
                 */
                System.out.println("[SERVICE] Prepare failed, notifying coordinator that we cannot complete");
                participantManager.cannotComplete();
            } catch (Exception e) {
                System.err.println("'cannotComplete' callback failed");
                throw new SetServiceException("Error when notifying the coordinator that the work is cannot be completed", e);
            }
            throw new SetServiceException("Unable to prepare the back-end resource");
View Full Code Here


    @WebMethod
    public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {

        log.info("[SERVICE] invoked addValueToSet('" + value + "')");

        BAParticipantManager participantManager;

        try {
            // enlist the Participant for this service:
            SetParticipantBA participant = new SetParticipantBA(value);
            BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
            log.info("[SERVICE] Enlisting a participant into the BA");
            participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(participant,
                    "SetServiceBAImpl:" + new Uid().toString());
        } catch (Exception e) {
            log.error("Participant enlistment failed");
            e.printStackTrace(System.err);
            throw new SetServiceException("Error enlisting participant", e);
        }

        // invoke the back-end business logic
        log.info("[SERVICE] Invoking the back-end business logic");
        MockSetManager.add(value);

        /*
         * this service employs the participant completion protocol which means it decides when it wants to commit local
         * changes. If the local changes (adding the item to the set) succeeded, we notify the coordinator that we have
         * completed. Otherwise, we notify the coordinator that we cannot complete. If any other participant fails or the client
         * decides to cancel we can rely upon being told to compensate.
         */
        log.info("[SERVICE] Prepare the backend resource and if successful notify the coordinator that we have completed our work");
        if (MockSetManager.prepare()) {
            try {
                // tell the coordinator manager we have finished our work
                log.info("[SERVICE] Prepare successful, notifying coordinator of completion");
                participantManager.completed();
            } catch (Exception e) {
                /*
                 * Failed to notify the coordinator that we have finished our work. Compensate the work and throw an Exception
                 * to notify the client that the add operation failed.
                 */
                MockSetManager.rollback(value);

                log.error("[SERVICE]  'completed' callback failed");
                throw new SetServiceException("Error when notifying the coordinator that the work is completed", e);
            }
        } else {
            try {
                /*
                 * tell the participant manager we cannot complete. this will force the activity to fail
                 */
                log.info("[SERVICE] Prepare failed, notifying coordinator that we cannot complete");
                participantManager.cannotComplete();
            } catch (Exception e) {
                log.error("'cannotComplete' callback failed");
                throw new SetServiceException("Error when notifying the coordinator that the work is cannot be completed", e);
            }
            throw new SetServiceException("Unable to prepare the back-end resource");
View Full Code Here

                // enlist the Participant for this service:
                participantBA = new BACoordinationCompletionParticipant(serviceCommands, eventLog, transactionId, value);
                BACoordinationCompletionParticipant.recordParticipant(transactionId, participantBA);

                log.info("[BA COORDINATOR COMPL SERVICE] Enlisting a participant into the BA");
                BAParticipantManager baParticipantManager =  activityManager.enlistForBusinessAgreementWithCoordinatorCompletion(participantBA,
                        "BACoordinatorCompletition:" + new Uid().toString());

                if (ServiceCommand.isPresent(CANNOT_COMPLETE, serviceCommands)) {
                    baParticipantManager.cannotComplete();
                    return;
                }
               
                if (ServiceCommand.isPresent(DO_COMPLETE, serviceCommands)) {
                    throw new RuntimeException("Only ParticipantCompletion participants are supposed to call complete. " +
View Full Code Here

    public void saveData(String value, ServiceCommand... serviceCommands) throws TestApplicationException {

        log.info("[BA PARTICIPANT COMPL SERVICE] invoked saveData('" + value + "')");
        eventLog.foundEventLogName(value);
       
        BAParticipantManager participantManager;
        BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
        String txid;
       
        try {
            txid = activityManager.currentTransaction().toString();
        } catch (SystemException se) {
            throw new RuntimeException("Error on getting TX id from BusinessActivityManager", se);
        }
       
        if(participantRegistry.keySet().contains(txid) && ServiceCommand.isPresent(REUSE_BA_PARTICIPANT, serviceCommands)) {
            log.info("[BA PARTICIPANT COMPL SERVICE] Reusing BA participant manager - command: " + REUSE_BA_PARTICIPANT);
            participantManager = participantRegistry.get(txid);
        } else {
            try {
                // Enlist the Participant for this service:
                BAParticipantCompletionParticipant participant = new BAParticipantCompletionParticipant(serviceCommands, eventLog, value);
                log.info("[BA PARTICIPANT COMPL SERVICE] Enlisting a participant into the BA");
                participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(participant,
                        "BAParticipantCompletition:" + new Uid().toString());
                participantRegistry.put(txid, participantManager);
            } catch (Exception e) {
                log.error("[BA PARTICIPANT COMPL SERVICE]  Participant enlistment failed", e);
                throw new RuntimeException("Error enlisting participant", e);
            }
        }

        if (ServiceCommand.isPresent(APPLICATION_EXCEPTION, serviceCommands)) {
            throw new TestApplicationException("Intentionally thrown Application Exception - service command set to: " + APPLICATION_EXCEPTION);
        }  
       
        // There could be invoked some back-end business logic here
       
        /*
         * This service employs the participant completion protocol which means it decides when it wants to commit local
         * changes. If the local changes (adding the item to the set) succeeded, we notify the coordinator that we have
         * completed. Otherwise, we notify the coordinator that we cannot complete. If any other participant fails or the client
         * decides to cancel we can rely upon being told to compensate.
         */
        log.info("[BA PARTICIPANT COMPL SERVICE] Prepare the backend resource and if successful notify the coordinator that we have completed our work");
        if (ServiceCommand.isPresent(DO_COMPLETE, serviceCommands)) {
            try {
                // Tell the coordinator manager we have finished our work
                log.info("[BA PARTICIPANT COMPL SERVICE] Prepare successful, notifying coordinator of completion");
                participantManager.completed();
            } catch (Exception e) {
                /* Failed to notify the coordinator that we have finished our work. Compensate the work and throw an Exception
                 * to notify the client that the add operation failed. */
                log.error("[BA PARTICIPANT COMPL SERVICE] 'completed' callback failed");
                throw new RuntimeException("Error when notifying the coordinator that the work is completed", e);
            }
        }
       
        if (ServiceCommand.isPresent(CANNOT_COMPLETE, serviceCommands)) {
            try {
                // Tell the participant manager we cannot complete. This will force the activity to fail.
                log.info("[BA PARTICIPANT COMPL SERVICE] Prepared fail, notifying coordinator that we cannot complete");
                participantManager.cannotComplete();
                return;
            } catch (Exception e) {
                log.error("[BA PARTICIPANT COMPL SERVICE] 'cannotComplete' callback failed");
                throw new RuntimeException("Error when notifying the coordinator that the work is cannot be completed", e);
            }
View Full Code Here

    @WebMethod
    public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {

        System.out.println("[SERVICE] invoked addValueToSet('" + value + "')");

        BAParticipantManager participantManager;

        try {
            // enlist the Participant for this service:
            SetParticipantBA participant = new SetParticipantBA(value);
            BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
            System.out.println("[SERVICE] Enlisting a participant into the BA");
            participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(participant,
                    "SetServiceBAImpl:" + UUID.randomUUID());
        } catch (Exception e) {
            System.err.println("Participant enlistment failed");
            e.printStackTrace(System.err);
            throw new SetServiceException("Error enlisting participant", e);
        }

        // invoke the back-end business logic
        System.out.println("[SERVICE] Invoking the back-end business logic");
        MockSetManager.add(value);

        /*
         * this service employs the participant completion protocol which means it decides when it wants to commit local
         * changes. If the local changes (adding the item to the set) succeeded, we notify the coordinator that we have
         * completed. Otherwise, we notify the coordinator that we cannot complete. If any other participant fails or the client
         * decides to cancel we can rely upon being told to compensate.
         */
        System.out
                .println("[SERVICE] Prepare the backend resource and if successful notify the coordinator that we have completed our work");
        if (MockSetManager.prepare()) {
            try {
                // tell the coordinator manager we have finished our work
                System.out.println("[SERVICE] Prepare successful, notifying coordinator of completion");
                participantManager.completed();
            } catch (Exception e) {
                /*
                 * Failed to notify the coordinator that we have finished our work. Compensate the work and throw an Exception
                 * to notify the client that the add operation failed.
                 */
                MockSetManager.rollback(value);

                System.err.println("[SERVICE]  'completed' callback failed");
                throw new SetServiceException("Error when notifying the coordinator that the work is completed", e);
            }
        } else {
            try {
                /*
                 * tell the participant manager we cannot complete. this will force the activity to fail
                 */
                System.out.println("[SERVICE] Prepare failed, notifying coordinator that we cannot complete");
                participantManager.cannotComplete();
            } catch (Exception e) {
                System.err.println("'cannotComplete' callback failed");
                throw new SetServiceException("Error when notifying the coordinator that the work is cannot be completed", e);
            }
            throw new SetServiceException("Unable to prepare the back-end resource");
View Full Code Here

            theatreView.addMessage("id:" + transactionId + ". Seats prepared, trying to commit and enlist compensation Participant");
            theatreView.updateFields();

            TheatreParticipantBA theatreParticipant = new TheatreParticipantBA(transactionId, how_many, which_area);
            // enlist the Participant for this service:
            BAParticipantManager participantManager = null;
            try
            {
                participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(theatreParticipant, "org.jboss.jbossts.xts-demo:restaurantBA:" + new Uid().toString());
            }
            catch (Exception e)
            {
                theatreView.addMessage("id:" + transactionId + ". Participant enrolement failed");
                theatreManager.cancelSeats(transactionId);
                System.err.println("bookSeats: Participant enrolement failed");
                e.printStackTrace(System.err);
                return false;
            }

            // finish the booking in the backend ensuring it is compensatable:
            theatreManager.commitSeats(transactionId, true);

            try
            {
                participantManager.completed();
            }
            catch (Exception e)
            {
                System.err.println("bookSeats: 'completed' callback failed");
                theatreManager.cancelSeats(transactionId);
View Full Code Here

                bindCommands(commandList, bindings);
                String id = participantId("CoordinatorCompletionParticipant");
                CoordinatorCompletionTestParticipant participant = new CoordinatorCompletionTestParticipant(id);
                BusinessActivityManager baman = BusinessActivityManagerFactory.businessActivityManager();
                try {
                    BAParticipantManager partMan;
                    partMan = baman.enlistForBusinessAgreementWithCoordinatorCompletion(participant, id);
                    managerMap.put(id, partMan);
                } catch (Exception e) {
                    throw new WebServiceException("enlistCoordinatorCompletion failed ", e);
                }
                for (idx = 0; idx < size; idx++) {
                    participant.addCommand(commandList.get(idx));
                }
                participantMap.put(id, participant);
                resultsList.add(id);
            } else if (command.equals("enlistParticipantCompletion")) {
                bindCommands(commandList, bindings);
                String id = participantId("ParticipantCompletionParticipant");
                ParticipantCompletionTestParticipant participant = new ParticipantCompletionTestParticipant(id);
                BusinessActivityManager baman = BusinessActivityManagerFactory.businessActivityManager();
                try {
                    BAParticipantManager partMan;
                    partMan = baman.enlistForBusinessAgreementWithParticipantCompletion(participant, id);
                    managerMap.put(id, partMan);
                } catch (Exception e) {
                    throw new WebServiceException("enlistParticipantCompletion failed ", e);
                }
                for (idx = 0; idx < size; idx++) {
                    participant.addCommand(commandList.get(idx));
                }
                participantMap.put(id, participant);
                resultsList.add(id);
            } else if (command.equals("addCommands")) {
// add extra commands to a participant script
                bindCommands(commandList, bindings);
                String id = commandList.remove(idx);
                size--;
                ScriptedTestParticipant participant = participantMap.get(id);
                if (participant != null) {
                    for (idx = 0; idx < size; idx++)
                    {
                        participant.addCommand(commandList.get(idx));
                    }
                    resultsList.add("ok");
                } else {
                    throw new WebServiceException("addCommands failed to find participant " + id);
                }
            } else if (command.equals("exit")) {
// initiate BA manager activities
                bindCommands(commandList, bindings);
                String id = commandList.remove(idx);
                size--;
                ScriptedTestParticipant participant = participantMap.get(id);
                if (participant != null ) {
                    if (participant instanceof ParticipantCompletionTestParticipant) {
                        ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant)participant;
                        BAParticipantManager manager = managerMap.get(id);
                        try {
                            manager.exit();
                        } catch (Exception e) {
                            throw new WebServiceException("exit " + id + " failed with exception " + e);
                        }
                        resultsList.add("ok");
                    } else {
                        throw new WebServiceException("exit invalid participant type " + id);
                    }
                } else {
                    throw new WebServiceException("exit unknown participant " + id);
                }
            } else if (command.equals("completed")) {
                bindCommands(commandList, bindings);
                String id = commandList.remove(idx);
                size--;
                ScriptedTestParticipant participant = participantMap.get(id);
                if (participant != null ) {
                    if (participant instanceof ParticipantCompletionTestParticipant) {
                        ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant)participant;
                        BAParticipantManager manager = managerMap.get(id);
                        try {
                            manager.completed();
                            resultsList.add("ok");
                        } catch (Exception e) {
                            throw new WebServiceException("completed " + id + " failed with exception " + e);
                        }
                    } else {
                        throw new WebServiceException("completed invalid participant type " + id);
                    }
                } else {
                    throw new WebServiceException("completed unknown participant " + id);
                }
            } else if (command.equals("fail")) {
                bindCommands(commandList, bindings);
                String id = commandList.remove(idx);
                size--;
                ScriptedTestParticipant participant = participantMap.get(id);
                if (participant != null ) {
                    if (participant instanceof ParticipantCompletionTestParticipant) {
                        ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant)participant;
                        BAParticipantManager manager = managerMap.get(id);
                        QName qname = new QName("http://jbossts.jboss.org/xts/servicetests/", "fail");
                        try {
                            manager.fail(qname);
                            resultsList.add("ok");
                        } catch (Exception e) {
                            throw new WebServiceException("fail " + id + " failed with exception " + e);
                        }
                    } else {
                        throw new WebServiceException("fail invalid participant type " + id);
                    }
                } else {
                    throw new WebServiceException("fail unknown participant " + id);
                }
            } else if (command.equals("cannotComplete")) {
                bindCommands(commandList, bindings);
                String id = commandList.remove(idx);
                size--;
                ScriptedTestParticipant participant = participantMap.get(id);
                if (participant != null ) {
                    if (participant instanceof ParticipantCompletionTestParticipant) {
                        ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant)participant;
                        BAParticipantManager manager = managerMap.get(id);
                        try {
                            manager.cannotComplete();
                            resultsList.add("ok");
                        } catch (Exception e) {
                            throw new WebServiceException("cannotComplete " + id + " failed with exception " + e);
                        }
                    } else {
View Full Code Here

            // it worked, so now we need a participant enlisted in case of compensation:

            RestaurantParticipantBA restaurantParticipant = new RestaurantParticipantBA(transactionId, how_many);
            // enlist the Participant for this service:
            BAParticipantManager participantManager = null;
            try
            {
                participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(restaurantParticipant, "org.jboss.jbossts.xts-demo:restaurantBA:" + new Uid().toString());
            }
            catch (Exception e)
            {
                restaurantView.addMessage("id:" + transactionId + ". Participant enrolement failed");
                restaurantManager.cancelSeats(transactionId);
                System.err.println("bookSeats: Participant enlistment failed");
                e.printStackTrace(System.err);
                return false;
            }

            // finish the booking in the backend ensuring it is compensatable:
            restaurantManager.commitSeats(transactionId, true);

            try
            {
                // tell the manager we have finished our work:
                participantManager.completed();
            }
            catch (Exception e)
            {
                System.err.println("bookSeats: 'completed' callback failed");
                restaurantManager.cancelSeats(transactionId);
View Full Code Here

            taxiView.updateFields();

            // it worked, so now we need a participant enlisted in case of compensation:
            TaxiParticipantBA taxiParticipant = new TaxiParticipantBA(transactionId);
            // enlist the Participant for this service:
            BAParticipantManager participantManager = null;
            try
            {
                participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(taxiParticipant, "org.jboss.jbossts.xts-demo:restaurantBA:" + new Uid().toString());
            }
            catch (Exception e)
            {
                taxiView.addMessage("id:" + transactionId + ". Participant enrolement failed");
                taxiManager.cancelTaxi(transactionId);
                System.err.println("bookTaxi: Participant enrolment failed");
                e.printStackTrace(System.err);
                return false;
            }

            // finish the booking in the backend ensuring it is compensatable:
            taxiManager.commitTaxi(transactionId, true);

            try
            {
                // tell the manager we have finished our work:
                participantManager.completed();
            }
            catch (Exception e)
            {
                System.err.println("bookTaxi: 'completed' callback failed");
                taxiManager.cancelTaxi(transactionId);
View Full Code Here

     */
    public void cancel(final NotificationType cancel, final AddressingProperties addressingProperties,
        final ArjunaContext arjunaContext)
    {
        final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier() ;
        final BusinessActivityTerminator participant = getParticipant(instanceIdentifier) ;

        try
        {
            if (participant != null)
            {
                W3CEndpointReference endpoint = participant.getEndpoint();

                final String messageId = MessageId.getMessageId() ;
                try
                {
                    participant.cancel() ;
                }
                catch (final FaultedException fe)
                {
                    final AddressingProperties responseAddressingProperties = AddressingHelper.createNotificationContext(messageId) ;
                    TerminationParticipantClient.getClient().sendFaulted(endpoint, responseAddressingProperties, instanceIdentifier) ;
View Full Code Here

TOP

Related Classes of com.arjuna.wst11.tests.junit.ba.Close

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.