001/*
002 * JGrapes Event Driven Framework
003 * Copyright (C) 2017-2018 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero General Public License as published by 
007 * the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 * 
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jgrapes.core;
020
021import org.jgrapes.core.internal.CompletionLockBase;
022import org.jgrapes.core.internal.EventBase;
023
024/**
025 * Represents a lock that prevents sending completion events. Completion
026 * locks can be added to events. They have the same effect as an event 
027 * that has been fired during the execution and that has not been processed
028 * yet.
029 * 
030 * Removing the last completion lock from an event after all events
031 * fired by its handlers have been processed will cause the completion
032 * events to be fired. 
033 * 
034 * @see EventBase#addCompletionLock
035 */
036public class CompletionLock extends CompletionLockBase {
037
038    /**
039     * Creates a completion lock for the given event with the given timeout. 
040     * 
041     * @param event the event to be locked
042     * @param timeout the timeout, if zero, the lock will be held up until
043     * it is released
044     */
045    public CompletionLock(Event<?> event, long timeout) {
046        super(event, timeout);
047    }
048
049    /**
050     * Creates a completion lock without timeout.
051     * 
052     * @param event the event to be locked
053     */
054    public CompletionLock(Event<?> event) {
055        super(event, 0);
056    }
057
058}