Search in sources :

Example 6 with SequenceType

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));
        }
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SequenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType) Work(org.hibernate.jdbc.Work) File(java.io.File) Session(org.hibernate.Session)

Example 7 with SequenceType

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());
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException)

Example 8 with SequenceType

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());
        }
    }
}
Also used : SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType)

Example 9 with SequenceType

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);
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) InputStream(java.io.InputStream) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Fault(org.apache.cxf.interceptor.Fault) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)

Example 10 with SequenceType

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());
}
Also used : CreateSequenceType(org.apache.cxf.ws.rm.v200702.CreateSequenceType) TerminateSequenceType(org.apache.cxf.ws.rm.v200702.TerminateSequenceType) CloseSequenceType(org.apache.cxf.ws.rm.v200702.CloseSequenceType) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)33 CloseSequenceType (org.apache.cxf.ws.rm.v200702.CloseSequenceType)12 RMProperties (org.apache.cxf.ws.rm.RMProperties)11 CreateSequenceType (org.apache.cxf.ws.rm.v200702.CreateSequenceType)11 TerminateSequenceType (org.apache.cxf.ws.rm.v200702.TerminateSequenceType)11 Message (org.apache.cxf.message.Message)8 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)7 SequenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType)6 IOException (java.io.IOException)6 Unmarshaller (javax.xml.bind.Unmarshaller)5 AckRequestedType (org.apache.cxf.ws.rm.v200702.AckRequestedType)5 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 Exchange (org.apache.cxf.message.Exchange)4 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)4 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)4 Test (org.junit.Test)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 File (java.io.File)3