com.arjuna.wst.messaging.CompletionCoordinatorProcessorImpl Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags.
* See the copyright.txt in the distribution for a full listing
* of individual contributors.
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* (C) 2005-2006,
* @author JBoss Inc.
*/
package com.arjuna.wst.messaging;
import com.arjuna.webservices.SoapFault;
import com.arjuna.webservices.SoapFault10;
import com.arjuna.webservices.SoapFaultType;
import com.arjuna.webservices.base.processors.ActivatedObjectProcessor;
import com.arjuna.webservices.logging.WSTLogger;
import com.arjuna.webservices.wsaddr.AddressingContext;
import com.arjuna.webservices.wsarj.ArjunaContext;
import com.arjuna.webservices.wsarj.InstanceIdentifier;
import com.arjuna.webservices.wsarjtx.ArjunaTXConstants;
import com.arjuna.webservices.wsat.NotificationType;
import com.arjuna.webservices.wsat.client.CompletionInitiatorClient;
import com.arjuna.webservices.wsat.processors.CompletionCoordinatorProcessor;
import com.arjuna.wsc.messaging.MessageId;
import com.arjuna.wst.CompletionCoordinatorParticipant;
import com.arjuna.wst.SystemException;
import com.arjuna.wst.TransactionRolledBackException;
import com.arjuna.wst.UnknownTransactionException;
/**
* The Completion Coordinator processor.
* @author kevin
*/
public class CompletionCoordinatorProcessorImpl extends CompletionCoordinatorProcessor
{
/**
* The activated object processor.
*/
private final ActivatedObjectProcessor activatedObjectProcessor = new ActivatedObjectProcessor() ;
/**
* Activate the participant.
* @param participant The participant.
* @param identifier The identifier.
*/
public void activateParticipant(final CompletionCoordinatorParticipant participant, final String identifier)
{
activatedObjectProcessor.activateObject(participant, identifier) ;
}
/**
* Deactivate the participant.
* @param participant The participant.
*/
public void deactivateParticipant(final CompletionCoordinatorParticipant participant)
{
activatedObjectProcessor.deactivateObject(participant) ;
}
/**
* Get the participant with the specified identifier.
* @param instanceIdentifier The participant identifier.
* @return The participant or null if not known.
*/
private CompletionCoordinatorParticipant getParticipant(final InstanceIdentifier instanceIdentifier)
{
final String identifier = (instanceIdentifier != null ? instanceIdentifier.getInstanceIdentifier() : null) ;
return (CompletionCoordinatorParticipant)activatedObjectProcessor.getObject(identifier) ;
}
/**
* Commit.
* @param commit The commit notification.
* @param addressingContext The addressing context.
* @param arjunaContext The arjuna context.
*/
public void commit(final NotificationType commit, final AddressingContext addressingContext,
final ArjunaContext arjunaContext)
{
final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier() ;
final CompletionCoordinatorParticipant participant = getParticipant(instanceIdentifier) ;
try
{
if (participant != null)
{
final String messageId = MessageId.getMessageId() ;
try
{
participant.commit() ;
}
catch (final TransactionRolledBackException trbe)
{
final AddressingContext responseAddressingContext =
AddressingContext.createNotificationContext(addressingContext, messageId) ;
CompletionInitiatorClient.getClient().sendAborted(responseAddressingContext, instanceIdentifier) ;
return ;
}
catch (final UnknownTransactionException ute)
{
final AddressingContext faultAddressingContext = AddressingContext.createFaultContext(addressingContext, messageId) ;
final SoapFault soapFault = new SoapFault10(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME,
WSTLogger.i18NLogger.get_messaging_CompletionCoordinatorProcessorImpl_1()) ;
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier) ;
return ;
}
catch (final SystemException se)
{
final AddressingContext faultAddressingContext = AddressingContext.createFaultContext(addressingContext, messageId) ;
final String message = WSTLogger.i18NLogger.get_messaging_CompletionCoordinatorProcessorImpl_2();
final SoapFault soapFault = new SoapFault10(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME, message) ;
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier) ;
return ;
}
catch (final Throwable th)
{
if (WSTLogger.logger.isTraceEnabled())
{
WSTLogger.logger.tracev("Unexpected exception thrown from commit:", th) ;
}
final AddressingContext faultAddressingContext = AddressingContext.createFaultContext(addressingContext, MessageId.getMessageId()) ;
final SoapFault soapFault = new SoapFault10(th) ;
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier) ;
return ;
}
final AddressingContext responseAddressingContext =
AddressingContext.createNotificationContext(addressingContext, messageId) ;
CompletionInitiatorClient.getClient().sendCommitted(responseAddressingContext, instanceIdentifier) ;
}
else
{
if (WSTLogger.logger.isTraceEnabled())
{
WSTLogger.logger.tracev("Commit called on unknown participant: {0}", new Object[] {instanceIdentifier}) ;
}
final AddressingContext faultAddressingContext = AddressingContext.createFaultContext(addressingContext, MessageId.getMessageId()) ;
final SoapFault soapFault = new SoapFault10(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME,
WSTLogger.i18NLogger.get_messaging_CompletionCoordinatorProcessorImpl_5()) ;
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier) ;
}
}
catch (Throwable throwable)
{
throwable.printStackTrace(System.err);
}
}
/**
* Rollback.
* @param rollback The rollback notification.
* @param addressingContext The addressing context.
* @param arjunaContext The arjuna context.
*/
public void rollback(final NotificationType rollback, final AddressingContext addressingContext,
final ArjunaContext arjunaContext)
{
final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier() ;
final CompletionCoordinatorParticipant participant = getParticipant(instanceIdentifier) ;
try
{
if (participant != null)
{
final String messageId = MessageId.getMessageId() ;
try
{
participant.rollback() ;
}
catch (final UnknownTransactionException ute)
{
final AddressingContext faultAddressingContext = AddressingContext.createFaultContext(addressingContext, messageId) ;
final SoapFault soapFault = new SoapFault10(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME,
WSTLogger.i18NLogger.get_messaging_CompletionCoordinatorProcessorImpl_6()) ;
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier) ;
return ;
}
catch (SystemException systemException)
{
final AddressingContext faultAddressingContext = AddressingContext.createFaultContext(addressingContext, messageId) ;
final String message = WSTLogger.i18NLogger.get_messaging_CompletionCoordinatorProcessorImpl_7();
final SoapFault soapFault = new SoapFault10(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME, message) ;
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier) ;
return ;
}
catch (final Throwable th)
{
if (WSTLogger.logger.isTraceEnabled())
{
WSTLogger.logger.tracev("Unexpected exception thrown from rollback:", th) ;
}
final AddressingContext faultAddressingContext = AddressingContext.createFaultContext(addressingContext, MessageId.getMessageId()) ;
final SoapFault soapFault = new SoapFault10(th) ;
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier) ;
return ;
}
final AddressingContext responseAddressingContext =
AddressingContext.createNotificationContext(addressingContext, messageId) ;
CompletionInitiatorClient.getClient().sendAborted(responseAddressingContext, instanceIdentifier) ;
}
else
{
if (WSTLogger.logger.isTraceEnabled())
{
WSTLogger.logger.tracev("Rollback called on unknown participant: {0}", new Object[] {instanceIdentifier}) ;
}
final AddressingContext faultAddressingContext = AddressingContext.createFaultContext(addressingContext, MessageId.getMessageId()) ;
final SoapFault soapFault = new SoapFault10(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME,
WSTLogger.i18NLogger.get_messaging_CompletionCoordinatorProcessorImpl_10()) ;
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier) ;
}
}
catch (Throwable throwable)
{
throwable.printStackTrace(System.err);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy