use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project midpoint by Evolveum.
the class SequenceTest method concurrencyUniversal.
private void concurrencyUniversal(String name, String sequenceFileName, long duration, WorkerThread[] workerThreads, boolean alwaysOrder) throws Exception {
Session session = getFactory().openSession();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
System.out.println(">>>>" + connection.getTransactionIsolation());
}
});
session.close();
final File file = new File(TEST_DIR + sequenceFileName);
PrismObject<SequenceType> sequence = prismContext.parseObject(file);
sequence.asObjectable().setName(new PolyStringType(name));
OperationResult result = new OperationResult("Concurrency Test");
String oid = repositoryService.addObject(sequence, null, result);
LOGGER.info("*** Object added: " + oid + " ***");
LOGGER.info("*** Starting modifier threads ***");
for (WorkerThread t : workerThreads) {
t.setOid(oid);
t.start();
}
LOGGER.info("*** Waiting " + duration + " ms ***");
Thread.sleep(duration);
for (WorkerThread t : workerThreads) {
t.stop = true;
}
long endTime = System.currentTimeMillis() + STOP_TIMEOUT;
for (; ; ) {
long remaining = endTime - System.currentTimeMillis();
if (remaining <= 0) {
break;
}
for (WorkerThread t : workerThreads) {
t.join(remaining);
remaining = endTime - System.currentTimeMillis();
if (remaining <= 0) {
break;
}
}
}
for (WorkerThread t : workerThreads) {
LOGGER.info("Worker thread {} finished after {} iterations with result: {}", t.id, t.counter, t.threadResult != null ? t.threadResult : "OK");
}
for (WorkerThread t : workerThreads) {
if (t.threadResult != null) {
throw new AssertionError("Worker thread " + t.id + " finished with an exception: " + t.threadResult, t.threadResult);
}
}
List<Long> allValues = new ArrayList<>();
for (WorkerThread t : workerThreads) {
allValues.addAll(t.values);
}
if (alwaysOrder || workerThreads.length > 1) {
Collections.sort(allValues);
}
LOGGER.trace("Checking a list of {} values", allValues.size());
for (int i = 0; i < allValues.size(); i++) {
if (allValues.get(i) != i) {
LOGGER.error("Incorrect value at position {}: {}", i, allValues.get(i));
for (WorkerThread t : workerThreads) {
LOGGER.info("Thread {}: {}", t.id, t.values);
}
fail("Incorrect value at position " + i + ": " + allValues.get(i));
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.
the class Destination method acknowledge.
/**
* Acknowledges receipt of a message. If the message is the last in the
* sequence, sends an out-of-band SequenceAcknowledgement unless there a
* response will be sent to the acksTo address onto which the acknowldegment
* can be piggybacked.
*
* @param sequenceType the sequenceType object that includes identifier and
* message number (and possibly a lastMessage element) for the
* message to be acknowledged)
* @param replyToAddress the replyTo address of the message that carried
* this sequence information
* @throws SequenceFault if the sequence specified in
* <code>sequenceType</code> does not exist
*/
public void acknowledge(Message message) throws SequenceFault, RMException {
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
SequenceType sequenceType = rmps.getSequence();
if (null == sequenceType) {
return;
}
DestinationSequence seq = getSequence(sequenceType.getIdentifier());
if (null != seq) {
if (seq.applyDeliveryAssurance(sequenceType.getMessageNumber(), message)) {
if (PropertyUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY))) {
return;
}
seq.acknowledge(message);
if (null != rmps.getCloseSequence()) {
seq.setLastMessageNumber(sequenceType.getMessageNumber());
ackImmediately(seq, message);
}
} else {
try {
message.getInterceptorChain().abort();
if (seq.sendAcknowledgement()) {
ackImmediately(seq, message);
}
Exchange exchange = message.getExchange();
Conduit conduit = exchange.getDestination().getBackChannel(message);
if (conduit != null) {
// null if it knows it cannot send anything.
if (seq.sendAcknowledgement()) {
AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
InternalContextUtils.rebaseResponse(null, maps, message);
} else {
Message response = createMessage(exchange);
response.setExchange(exchange);
response.remove(Message.CONTENT_TYPE);
conduit.prepare(response);
conduit.close(response);
}
}
} catch (IOException e) {
LOG.log(Level.SEVERE, e.getMessage());
throw new RMException(e);
}
}
} else {
ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
RMConstants consts = protocol.getConstants();
SequenceFaultFactory sff = new SequenceFaultFactory(consts);
throw sff.createUnknownSequenceFault(sequenceType.getIdentifier());
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.
the class Destination method releaseDeliveringStatus.
void releaseDeliveringStatus(Message message) {
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
SequenceType sequenceType = rmps.getSequence();
if (null != sequenceType) {
DestinationSequence seq = getSequence(sequenceType.getIdentifier());
if (null != seq) {
seq.removeDeliveringMessageNumber(sequenceType.getMessageNumber());
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.
the class DestinationSequence method acknowledge.
public void acknowledge(Message message) throws SequenceFault {
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
SequenceType st = rmps.getSequence();
long messageNumber = st.getMessageNumber().longValue();
LOG.fine("Acknowledging message: " + messageNumber);
if (0 != lastMessageNumber && messageNumber > lastMessageNumber) {
RMConstants consts = getProtocol().getConstants();
SequenceFaultFactory sff = new SequenceFaultFactory(consts);
throw sff.createSequenceTerminatedFault(st.getIdentifier(), false);
}
monitor.acknowledgeMessage();
boolean updated = false;
synchronized (this) {
boolean done = false;
int i = 0;
for (; i < acknowledgement.getAcknowledgementRange().size(); i++) {
AcknowledgementRange r = acknowledgement.getAcknowledgementRange().get(i);
if (r.getLower().compareTo(messageNumber) <= 0 && r.getUpper().compareTo(messageNumber) >= 0) {
done = true;
break;
}
long diff = r.getLower() - messageNumber;
if (diff == 1) {
r.setLower(messageNumber);
updated = true;
done = true;
} else if (diff > 0) {
break;
} else if (messageNumber - r.getUpper().longValue() == 1) {
r.setUpper(messageNumber);
updated = true;
done = true;
break;
}
}
if (!done) {
// need new acknowledgement range
AcknowledgementRange range = new AcknowledgementRange();
range.setLower(messageNumber);
range.setUpper(messageNumber);
updated = true;
acknowledgement.getAcknowledgementRange().add(i, range);
if (acknowledgement.getAcknowledgementRange().size() > 1) {
// acknowledge out-of-order at first opportunity
scheduleImmediateAcknowledgement();
}
}
mergeRanges();
}
if (updated) {
RMStore store = destination.getManager().getStore();
if (null != store && !MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY)) {
try {
RMMessage msg = new RMMessage();
CachedOutputStream cos = (CachedOutputStream) message.get(RMMessageConstants.SAVED_CONTENT);
msg.setMessageNumber(st.getMessageNumber());
msg.setCreatedTime(rmps.getCreatedTime());
// in case no attachments are available, cos can be saved directly
if (message.getAttachments() == null) {
msg.setContent(cos);
msg.setContentType((String) message.get(Message.CONTENT_TYPE));
} else {
InputStream is = cos.getInputStream();
PersistenceUtils.encodeRMContent(msg, message, is);
}
store.persistIncoming(this, msg);
} catch (IOException e) {
throw new Fault(e);
}
}
}
deliveringMessageNumbers.add(messageNumber);
RMEndpoint reliableEndpoint = destination.getReliableEndpoint();
RMConfiguration cfg = reliableEndpoint.getConfiguration();
if (null == rmps.getCloseSequence()) {
scheduleAcknowledgement(cfg.getAcknowledgementIntervalTime());
}
long inactivityTimeout = cfg.getInactivityTimeoutTime();
scheduleSequenceTermination(inactivityTimeout);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.
the class EncoderDecoder10AImpl method decodeSequenceType.
public SequenceType decodeSequenceType(Element elem) throws JAXBException {
Unmarshaller unmarshaller = getContext().createUnmarshaller();
JAXBElement<org.apache.cxf.ws.rm.v200502wsa15.SequenceType> jaxbElement = unmarshaller.unmarshal(elem, org.apache.cxf.ws.rm.v200502wsa15.SequenceType.class);
return VersionTransformer.convert(jaxbElement.getValue());
}
Aggregations