001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020
021package org.apache.directory.server.ldap.replication.consumer;
022
023
024import org.apache.directory.server.core.api.DirectoryService;
025import org.apache.directory.server.ldap.replication.ReplicationConsumerConfig;
026
027
028/**
029 * An interface for consumers of a service which receives the ldap entries as and when a 
030 * event happens in the server. The data received might vary based on the internal configuration
031 * used by implementation.
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public interface ReplicationConsumer
036{
037    /** A flag we used when we want to connect without waiting */
038    boolean NOW = true;
039    
040    /** A flag we used when we want to connect after a waiting delay */
041    boolean DIFFERED = false;
042    
043    /**
044     * Sets the configuration of the consumer
045     * 
046     * @param config the configuration of the consumer
047     */
048    void setConfig( ReplicationConsumerConfig config );
049
050
051    /**
052     * @return get the configuration of the consumer
053     */
054    ReplicationConsumerConfig getConfig();
055
056
057    /**
058     * Initializes the consumer
059     * 
060     * @param dirService the DirectoryService
061     * @throws Exception If the initialization failed
062     */
063    void init( DirectoryService dirService ) throws Exception;
064
065
066    /**
067     * Connect the consumer, connection immediately or wait before reconnection
068     * 
069     * @param now A param that tells the consumer to connect immediately or not
070     * @return true if the consumer is connected, false otherwise
071     */
072    boolean connect( boolean now );
073    
074    
075    /**
076     * Test the connection with the provider. It does connect to the provider, and
077     * tries to bind on it using the consumer credentials.
078     */
079    void ping();
080
081
082    /**
083     * Stops the consumer
084     */
085    void stop();
086
087
088    /**
089     * @return the identifier of the consumer instance
090     */
091    String getId();
092
093    
094    /**
095     * Starts the synchronization operation
096     * 
097     * @return The replication status
098     */
099    ReplicationStatusEnum startSync();
100}