Example usage for org.joda.time Duration millis

List of usage examples for org.joda.time Duration millis

Introduction

In this page you can find the example usage for org.joda.time Duration millis.

Prototype

public static Duration millis(long millis) 

Source Link

Document

Create a duration with the specified number of milliseconds.

Usage

From source file:org.talend.components.jms.runtime_1_1.JmsInputPTransformRuntime.java

License:Open Source License

@Override
public PCollection expand(PBegin pBegin) {

    datastoreRuntime = new JmsDatastoreRuntime();
    datastoreRuntime.initialize(null, properties.datasetRef.getReference().getDatastoreProperties());

    JmsIO.Read read = JmsIO.read().withConnectionFactory(datastoreRuntime.getConnectionFactory());
    if (messageType.equals(JmsMessageType.QUEUE)) {
        read = read.withQueue(properties.datasetRef.getReference().queueTopicName.getValue());
    } else if (messageType.equals(JmsMessageType.TOPIC)) {
        read = read.withTopic(properties.datasetRef.getReference().queueTopicName.getValue());
    }/*w  w w  . j  a  v  a 2 s .  com*/

    if (properties.max_msg.getValue() != -1 && properties.timeout.getValue() != -1) {
        read = read.withMaxNumRecords(properties.max_msg.getValue())
                .withMaxReadTime(Duration.millis(properties.timeout.getValue()));
    } else if (properties.max_msg.getValue() != -1) {
        read = read.withMaxNumRecords(properties.max_msg.getValue());
    } else if (properties.timeout.getValue() != -1) {
        read = read.withMaxReadTime(Duration.millis(properties.timeout.getValue()));
    }
    PCollection<JmsRecord> jmsCollection = pBegin.apply(read);

    if (jmsCollection != null) {
        PCollection<String> outputCollection = jmsCollection.apply("JmsRecordToIndexedRecord",
                ParDo.of(new DoFn<JmsRecord, String>() {

                    @DoFn.ProcessElement
                    public void processElement(ProcessContext c) throws Exception {
                        c.output(c.element().getPayload());
                    }
                }));
        return outputCollection;
    }
    return null;
}

From source file:org.talend.components.processing.runtime.window.WindowRuntime.java

License:Open Source License

@Override
public PCollection<IndexedRecord> expand(PCollection<IndexedRecord> indexedRecordPCollection) {
    PCollection<IndexedRecord> windowed_items;

    if (properties.windowLength.getValue() < 1) {
        TalendRuntimeException.build(CommonErrorCodes.UNEXPECTED_ARGUMENT).setAndThrow(
                properties.windowLength.getName(), String.valueOf(properties.windowLength.getValue()));
    }//from   w w w.  j  av  a2  s . c  o m

    // Session Window
    if (properties.windowSession.getValue()) {
        windowed_items = indexedRecordPCollection.apply(Window.<IndexedRecord>into(
                Sessions.withGapDuration(Duration.millis(properties.windowLength.getValue().intValue()))));
        return windowed_items;
    }

    if (properties.windowSlideLength.getValue() < 1) {
        // Fixed Window
        windowed_items = indexedRecordPCollection.apply(Window.<IndexedRecord>into(
                FixedWindows.of(new Duration(properties.windowLength.getValue().intValue()))));
    } else {
        // Sliding Window
        windowed_items = indexedRecordPCollection.apply(Window.<IndexedRecord>into(
                SlidingWindows.of(new Duration(properties.windowLength.getValue().intValue()))
                        .every(new Duration(properties.windowSlideLength.getValue().intValue()))));
    }
    return windowed_items;
}

From source file:org.talend.components.processing.runtime.WindowRuntime.java

License:Open Source License

@Override
public PCollection<IndexedRecord> expand(PCollection<IndexedRecord> indexedRecordPCollection) {
    PCollection<IndexedRecord> windowed_items;

    if (properties.windowLength.getValue() < 1) {
        throw new TalendRuntimeException(CommonErrorCodes.UNEXPECTED_ARGUMENT);
    }/*from   w w  w  . j  a  va 2s .c  o  m*/

    // Session Window
    if (properties.windowSession.getValue()) {
        windowed_items = indexedRecordPCollection.apply(Window.<IndexedRecord>into(
                Sessions.withGapDuration(Duration.millis(properties.windowLength.getValue().intValue()))));
        return windowed_items;
    }

    if (properties.windowSlideLength.getValue() < 1) {
        // Fixed Window
        windowed_items = indexedRecordPCollection.apply(Window.<IndexedRecord>into(
                FixedWindows.of(new Duration(properties.windowLength.getValue().intValue()))));
    } else {
        // Sliding Window
        windowed_items = indexedRecordPCollection.apply(Window.<IndexedRecord>into(
                SlidingWindows.of(new Duration(properties.windowLength.getValue().intValue()))
                        .every(new Duration(properties.windowSlideLength.getValue().intValue()))));
    }
    return windowed_items;
}