use of org.apache.cxf.ws.rm.v200702.SequenceType in project midpoint by Evolveum.
the class SequenceHelper method advanceSequenceAttempt.
public long advanceSequenceAttempt(String oid, OperationResult result) throws ObjectNotFoundException, SchemaException, SerializationRelatedException {
long returnValue;
LOGGER.debug("Advancing sequence with oid '{}'.", oid);
LOGGER_PERFORMANCE.debug("> advance sequence, oid={}", oid);
Session session = null;
try {
session = baseHelper.beginTransaction();
PrismObject<SequenceType> prismObject = objectRetriever.getObjectInternal(session, SequenceType.class, oid, null, true);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("OBJECT before:\n{}", prismObject.debugDump());
}
SequenceType sequence = prismObject.asObjectable();
if (!sequence.getUnusedValues().isEmpty()) {
returnValue = sequence.getUnusedValues().remove(0);
} else {
long counter = sequence.getCounter() != null ? sequence.getCounter() : 0L;
long maxCounter = sequence.getMaxCounter() != null ? sequence.getMaxCounter() : Long.MAX_VALUE;
boolean allowRewind = Boolean.TRUE.equals(sequence.isAllowRewind());
if (counter < maxCounter) {
returnValue = counter;
sequence.setCounter(counter + 1);
} else if (counter == maxCounter) {
returnValue = counter;
if (allowRewind) {
sequence.setCounter(0L);
} else {
// will produce exception during next run
sequence.setCounter(counter + 1);
}
} else {
// i.e. counter > maxCounter
if (allowRewind) {
// shouldn't occur but...
LOGGER.warn("Sequence {} overflown with allowRewind set to true. Rewinding.", oid);
returnValue = 0;
sequence.setCounter(1L);
} else {
// TODO some better exception...
throw new SystemException("No (next) value available from sequence " + oid + ". Current counter = " + sequence.getCounter() + ", max value = " + sequence.getMaxCounter());
}
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Return value = {}, OBJECT after:\n{}", returnValue, prismObject.debugDump());
}
// merge and update object
LOGGER.trace("Translating JAXB to data type.");
PrismIdentifierGenerator idGenerator = new PrismIdentifierGenerator(PrismIdentifierGenerator.Operation.MODIFY);
RObject rObject = objectUpdater.createDataObjectFromJAXB(prismObject, idGenerator);
rObject.setVersion(rObject.getVersion() + 1);
objectUpdater.updateFullObject(rObject, prismObject);
session.merge(rObject);
LOGGER.trace("Before commit...");
session.getTransaction().commit();
LOGGER.trace("Committed!");
return returnValue;
} catch (ObjectNotFoundException | SchemaException ex) {
baseHelper.rollbackTransaction(session, ex, result, true);
throw ex;
} catch (DtoTranslationException | RuntimeException ex) {
// should always throw an exception
baseHelper.handleGeneralException(ex, session, result);
// ...so this shouldn't occur at all
throw new SystemException("Exception " + ex + " was not handled correctly", ex);
} finally {
baseHelper.cleanupSessionAndResult(session, result);
LOGGER.trace("Session cleaned up.");
}
}
use of org.apache.cxf.ws.rm.v200702.SequenceType in project midpoint by Evolveum.
the class SequenceHelper method returnUnusedValuesToSequenceAttempt.
public void returnUnusedValuesToSequenceAttempt(String oid, Collection<Long> unusedValues, OperationResult result) throws ObjectNotFoundException, SchemaException, SerializationRelatedException {
LOGGER.debug("Returning unused values of {} to a sequence with oid '{}'.", unusedValues, oid);
LOGGER_PERFORMANCE.debug("> return unused values, oid={}, values={}", oid, unusedValues);
Session session = null;
try {
session = baseHelper.beginTransaction();
PrismObject<SequenceType> prismObject = objectRetriever.getObjectInternal(session, SequenceType.class, oid, null, true);
LOGGER.trace("OBJECT before:\n{}", prismObject.debugDumpLazily());
SequenceType sequence = prismObject.asObjectable();
int maxUnusedValues = sequence.getMaxUnusedValues() != null ? sequence.getMaxUnusedValues() : 0;
Iterator<Long> valuesToReturnIterator = unusedValues.iterator();
while (valuesToReturnIterator.hasNext() && sequence.getUnusedValues().size() < maxUnusedValues) {
Long valueToReturn = valuesToReturnIterator.next();
if (valueToReturn == null) {
// sanity check
continue;
}
if (!sequence.getUnusedValues().contains(valueToReturn)) {
sequence.getUnusedValues().add(valueToReturn);
} else {
LOGGER.warn("UnusedValues in sequence {} already contains value of {} - ignoring the return request", oid, valueToReturn);
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("OBJECT after:\n{}", prismObject.debugDump());
}
// merge and update object
LOGGER.trace("Translating JAXB to data type.");
PrismIdentifierGenerator idGenerator = new PrismIdentifierGenerator(PrismIdentifierGenerator.Operation.MODIFY);
RObject rObject = objectUpdater.createDataObjectFromJAXB(prismObject, idGenerator);
rObject.setVersion(rObject.getVersion() + 1);
objectUpdater.updateFullObject(rObject, prismObject);
session.merge(rObject);
LOGGER.trace("Before commit...");
session.getTransaction().commit();
LOGGER.trace("Committed!");
} catch (ObjectNotFoundException | SchemaException ex) {
baseHelper.rollbackTransaction(session, ex, result, true);
throw ex;
} catch (DtoTranslationException | RuntimeException ex) {
// should always throw an exception
baseHelper.handleGeneralException(ex, session, result);
// ...so this shouldn't occur at all
throw new SystemException("Exception " + ex + " was not handled correctly", ex);
} finally {
baseHelper.cleanupSessionAndResult(session, result);
LOGGER.trace("Session cleaned up.");
}
}
use of org.apache.cxf.ws.rm.v200702.SequenceType in project cxf by apache.
the class RMSoapInInterceptorTest method testDecodeAcksRequested.
@Test
public void testDecodeAcksRequested() throws XMLStreamException {
SoapMessage message = setUpInboundMessage("resources/Retransmission.xml");
RMSoapInInterceptor codec = new RMSoapInInterceptor();
codec.handleMessage(message);
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
Collection<AckRequestedType> requested = rmps.getAcksRequested();
assertNotNull(requested);
assertEquals(1, requested.size());
AckRequestedType ar = requested.iterator().next();
assertNotNull(ar);
assertEquals(ar.getIdentifier().getValue(), SEQ_IDENTIFIER);
SequenceType s = rmps.getSequence();
assertNotNull(s);
assertEquals(s.getIdentifier().getValue(), SEQ_IDENTIFIER);
assertEquals(s.getMessageNumber(), MSG2_MESSAGE_NUMBER);
assertNull(rmps.getAcks());
}
use of org.apache.cxf.ws.rm.v200702.SequenceType in project cxf by apache.
the class RMSoapInInterceptorTest method testDecodeSequence.
@Test
public void testDecodeSequence() throws XMLStreamException {
SoapMessage message = setUpInboundMessage("resources/Message1.xml");
RMSoapInInterceptor codec = new RMSoapInInterceptor();
codec.handleMessage(message);
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
SequenceType st = rmps.getSequence();
assertNotNull(st);
assertEquals(st.getIdentifier().getValue(), SEQ_IDENTIFIER);
assertEquals(st.getMessageNumber(), MSG1_MESSAGE_NUMBER);
assertNull(rmps.getAcks());
assertNull(rmps.getAcksRequested());
}
use of org.apache.cxf.ws.rm.v200702.SequenceType in project cxf by apache.
the class Destination method processingComplete.
void processingComplete(Message message) {
SequenceType sequenceType = RMContextUtils.retrieveRMProperties(message, false).getSequence();
if (null == sequenceType) {
return;
}
DestinationSequence seq = getSequence(sequenceType.getIdentifier());
if (null != seq) {
long mn = sequenceType.getMessageNumber().longValue();
seq.processingComplete(mn);
seq.purgeAcknowledged(mn);
// remove acknowledged undelivered message
seq.removeDeliveringMessageNumber(mn);
if (seq.isTerminated() && seq.allAcknowledgedMessagesDelivered()) {
removeSequence(seq);
}
}
CachedOutputStream saved = (CachedOutputStream) message.remove(RMMessageConstants.SAVED_CONTENT);
if (saved != null) {
saved.releaseTempFileHold();
try {
saved.close();
} catch (IOException e) {
// ignore
}
}
}
Aggregations