001/*
002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     tiry
018 */
019package org.nuxeo.ecm.core.event.pipe.local;
020
021import org.nuxeo.common.annotation.Experimental;
022import org.nuxeo.ecm.core.event.EventBundle;
023import org.nuxeo.ecm.core.event.pipe.AbstractEventBundlePipe;
024import org.nuxeo.ecm.core.event.pipe.EventBundlePipe;
025
026import java.util.Collections;
027import java.util.List;
028import java.util.Map;
029
030/**
031 * Local In memory implementation: directly relays to WorkManager
032 *
033 * @since 8.4
034 */
035@Experimental
036public class LocalEventBundlePipe extends AbstractEventBundlePipe<EventBundle> implements EventBundlePipe {
037
038    protected LocalEventBundlePipeConsumer consumer;
039
040    @Override
041    public void initPipe(String name, Map<String, String> params) {
042        super.initPipe(name, params);
043        consumer = new LocalEventBundlePipeConsumer();
044        consumer.initConsumer(name, params);
045    }
046
047    @Override
048    protected void send(EventBundle message) {
049        List<EventBundle> messages = Collections.singletonList(message);
050        consumer.receiveMessage(messages);
051    }
052
053    @Override
054    protected EventBundle marshall(EventBundle events) {
055        return events;
056    }
057
058    @Override
059    public boolean waitForCompletion(long timeoutMillis) throws InterruptedException {
060        return consumer.waitForCompletion(timeoutMillis);
061    }
062
063}