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.shared.ldap.extras.extended;
021
022
023import org.apache.directory.shared.i18n.I18n;
024import org.apache.directory.shared.ldap.model.message.ExtendedResponseImpl;
025import org.apache.directory.shared.ldap.model.message.Referral;
026import org.apache.directory.shared.ldap.model.message.ReferralImpl;
027import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
028
029
030/**
031 * An unsolicited notification, extended response, intended for notifying
032 * clients of up coming disconnection due to intended service windows. Unlike the
033 * {@link org.apache.directory.shared.ldap.model.message.extended.NoticeOfDisconnect} this response contains additional information about
034 * the amount of time the server will be offline and exactly when it intends to
035 * shutdown.
036 * 
037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038 */
039public class GracefulDisconnectResponseImpl extends ExtendedResponseImpl implements GracefulDisconnectResponse
040{
041    /** The serialVersionUID. */
042    private static final long serialVersionUID = -4682291068700593492L;
043
044    /** Offline time after disconnection */
045    private int timeOffline;
046
047    /** Delay before disconnection */
048    private int delay;
049
050    /** String based LDAP URL that may be followed for replicated namingContexts */
051    private Referral replicatedContexts = new ReferralImpl();
052
053
054    /**
055     * Instantiates a new graceful disconnect.
056     */
057    public GracefulDisconnectResponseImpl()
058    {
059        super( 0, EXTENSION_OID );
060    }
061
062
063    /**
064     * Instantiates a new graceful disconnect.
065     *
066     * @param timeOffline the offline time after disconnect, in minutes
067     * @param delay the delay before disconnect, in seconds
068     */
069    public GracefulDisconnectResponseImpl( int timeOffline, int delay )
070    {
071        super( 0, EXTENSION_OID );
072        responseName = EXTENSION_OID;
073        this.timeOffline = timeOffline;
074        this.delay = delay;
075
076        StringBuffer buf = new StringBuffer();
077        buf.append( "The server will disconnect and will be unavailable for " ).append( timeOffline );
078        buf.append( " minutes in " ).append( delay ).append( " seconds." );
079
080        ldapResult.setDiagnosticMessage( buf.toString() );
081        ldapResult.setMatchedDn( null );
082        ldapResult.setResultCode( ResultCodeEnum.UNAVAILABLE );
083    }
084
085
086    /**
087     * Gets the OID uniquely identifying this extended response (a.k.a. its
088     * name).
089     * 
090     * @return the OID of the extended response type.
091     */
092    public String getResponseName()
093    {
094        return EXTENSION_OID;
095    }
096
097
098    /**
099     * Sets the OID uniquely identifying this extended response (a.k.a. its
100     * name).
101     * 
102     * @param oid the OID of the extended response type.
103     */
104    public void setResponseName( String oid )
105    {
106        throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) );
107    }
108
109
110    // -----------------------------------------------------------------------
111    // Parameters of the Extended Response Value
112    // -----------------------------------------------------------------------
113
114    
115    /* (non-Javadoc)
116     * @see org.apache.directory.shared.ldap.extras.extended.GracefulDisconnectResponse#getDelay()
117     */
118    public int getDelay()
119    {
120        return delay;
121    }
122
123
124    /* (non-Javadoc)
125     * @see org.apache.directory.shared.ldap.extras.extended.GracefulDisconnectResponse#setDelay(int)
126     */
127    public void setDelay( int delay )
128    {
129        this.delay = delay;
130    }
131
132
133    /* (non-Javadoc)
134     * @see org.apache.directory.shared.ldap.extras.extended.GracefulDisconnectResponse#getTimeOffline()
135     */
136    public int getTimeOffline()
137    {
138        return timeOffline;
139    }
140
141
142    /* (non-Javadoc)
143     * @see org.apache.directory.shared.ldap.extras.extended.GracefulDisconnectResponse#setTimeOffline(int)
144     */
145    public void setTimeOffline( int timeOffline )
146    {
147        this.timeOffline = timeOffline;
148    }
149
150
151    /* (non-Javadoc)
152     * @see org.apache.directory.shared.ldap.extras.extended.GracefulDisconnectResponse#getReplicatedContexts()
153     */
154    public Referral getReplicatedContexts()
155    {
156        return replicatedContexts;
157    }
158}