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 */
020package org.apache.directory.api.ldap.extras.extended.gracefulShutdown;
021
022
023import org.apache.directory.api.ldap.model.message.AbstractExtendedRequest;
024
025
026/**
027 * An extended operation requesting the server to shutdown it's LDAP service
028 * port while allowing established clients to complete or abandon operations
029 * already in progress. More information about this extended request is
030 * available here: <a href="http://docs.safehaus.org:8080/x/GR">LDAP Extensions
031 * for Graceful Shutdown</a>.
032 * 
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class GracefulShutdownRequestImpl extends AbstractExtendedRequest implements GracefulShutdownRequest
036{
037    private GracefulShutdownResponse response;
038
039    /** Offline time after disconnection */
040    private int timeOffline;
041
042    /** Delay before disconnection */
043    private int delay;
044
045
046    /**
047     * Instantiates a new graceful shutdown request.
048     *
049     * @param messageId the message id
050     */
051    public GracefulShutdownRequestImpl( int messageId )
052    {
053        this( messageId, UNDETERMINED, NOW );
054    }
055
056
057    /**
058     * Instantiates a new graceful shutdown request.
059     *
060     * @param messageId the message id
061     */
062    public GracefulShutdownRequestImpl()
063    {
064        setRequestName( EXTENSION_OID );
065    }
066
067
068    /**
069     * Instantiates a new graceful shutdown request.
070     *
071     * @param messageId the message id
072     * @param timeOffline the offline time after disconnection, in minutes
073     * @param delay the delay before disconnection, in seconds
074     */
075    public GracefulShutdownRequestImpl( int messageId, int timeOffline, int delay )
076    {
077        super( messageId );
078        setRequestName( EXTENSION_OID );
079        this.timeOffline = timeOffline;
080        this.delay = delay;
081    }
082
083
084    // -----------------------------------------------------------------------
085    // Parameters of the Extended Request Payload
086    // -----------------------------------------------------------------------
087
088    /**
089     * {@inheritDoc}
090     */
091    public int getDelay()
092    {
093        return delay;
094    }
095
096
097    /**
098     * {@inheritDoc}
099     */
100    public void setDelay( int delay )
101    {
102        this.delay = delay;
103    }
104
105
106    /**
107     * {@inheritDoc}
108     */
109    public int getTimeOffline()
110    {
111        return timeOffline;
112    }
113
114
115    /**
116     * {@inheritDoc}
117     */
118    public void setTimeOffline( int timeOffline )
119    {
120        this.timeOffline = timeOffline;
121    }
122
123
124    @Override
125    public GracefulShutdownResponse getResultResponse()
126    {
127        if ( response == null )
128        {
129            response = new GracefulShutdownResponseImpl();
130        }
131
132        return response;
133    }
134}