001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.broker;
018
019import java.io.IOException;
020
021import org.apache.activemq.Service;
022import org.apache.activemq.store.PersistenceAdapter;
023
024/**
025 * Represents a lock service to ensure that a broker is the only master
026 */
027public interface Locker extends Service {
028
029    /**
030     * Used by a timer to keep alive the lock.
031     * If the method returns false the broker should be terminated
032     * if an exception is thrown, the lock state cannot be determined
033     */
034    boolean keepAlive() throws IOException;
035
036    /**
037     * set the delay interval in milliseconds between lock acquire attempts
038     *
039     * @param lockAcquireSleepInterval the sleep interval in miliseconds
040     */
041    void setLockAcquireSleepInterval(long lockAcquireSleepInterval);
042
043    /**
044     * Set the name of the lock to use.
045     */
046    public void setName(String name);
047
048    /**
049     * Specify whether to fail immediately if the lock is already held.  When set, the CustomLock must throw an
050     * IOException immediately upon detecting the lock is already held.
051     *
052     * @param failIfLocked: true => fail immediately if the lock is held; false => block until the lock can be obtained
053     *                      (default).
054     */
055    public void setFailIfLocked(boolean failIfLocked);
056
057    /**
058     * A reference to what is locked
059     */
060    public void setLockable(LockableServiceSupport lockable);
061
062    /**
063     * Optionally configure the locker with the persistence adapter currently used
064     * You can use persistence adapter configuration details like, data directory
065     * datasource, etc. to be used by the locker
066     *
067     * @param persistenceAdapter
068     * @throws IOException
069     */
070    public void configure(PersistenceAdapter persistenceAdapter) throws IOException;
071
072}