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.gracefulDisconnect; 021 022 023import org.apache.directory.api.i18n.I18n; 024import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl; 025import org.apache.directory.api.ldap.model.message.Referral; 026import org.apache.directory.api.ldap.model.message.ReferralImpl; 027import org.apache.directory.api.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.api.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 /** Offline time after disconnection */ 042 private int timeOffline; 043 044 /** Delay before disconnection */ 045 private int delay; 046 047 /** String based LDAP URL that may be followed for replicated namingContexts */ 048 private Referral replicatedContexts = new ReferralImpl(); 049 050 051 /** 052 * Instantiates a new graceful disconnect. 053 */ 054 public GracefulDisconnectResponseImpl() 055 { 056 super( 0, EXTENSION_OID ); 057 } 058 059 060 /** 061 * Instantiates a new graceful disconnect. 062 * 063 * @param timeOffline the offline time after disconnect, in minutes 064 * @param delay the delay before disconnect, in seconds 065 */ 066 public GracefulDisconnectResponseImpl( int timeOffline, int delay ) 067 { 068 super( 0, EXTENSION_OID ); 069 responseName = EXTENSION_OID; 070 this.timeOffline = timeOffline; 071 this.delay = delay; 072 073 StringBuilder buf = new StringBuilder(); 074 buf.append( "The server will disconnect and will be unavailable for " ).append( timeOffline ); 075 buf.append( " minutes in " ).append( delay ).append( " seconds." ); 076 077 ldapResult.setDiagnosticMessage( buf.toString() ); 078 ldapResult.setMatchedDn( null ); 079 ldapResult.setResultCode( ResultCodeEnum.UNAVAILABLE ); 080 } 081 082 083 /** 084 * Gets the OID uniquely identifying this extended response (a.k.a. its 085 * name). 086 * 087 * @return the OID of the extended response type. 088 */ 089 @Override 090 public String getResponseName() 091 { 092 return EXTENSION_OID; 093 } 094 095 096 /** 097 * Sets the OID uniquely identifying this extended response (a.k.a. its 098 * name). 099 * 100 * @param oid the OID of the extended response type. 101 */ 102 @Override 103 public void setResponseName( String oid ) 104 { 105 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) ); 106 } 107 108 109 // ----------------------------------------------------------------------- 110 // Parameters of the Extended Response Value 111 // ----------------------------------------------------------------------- 112 /** 113 * {@inheritDoc} 114 */ 115 @Override 116 public int getDelay() 117 { 118 return delay; 119 } 120 121 122 /** 123 * {@inheritDoc} 124 */ 125 @Override 126 public void setDelay( int delay ) 127 { 128 this.delay = delay; 129 } 130 131 132 /** 133 * {@inheritDoc} 134 */ 135 @Override 136 public int getTimeOffline() 137 { 138 return timeOffline; 139 } 140 141 142 /** 143 * {@inheritDoc} 144 */ 145 @Override 146 public void setTimeOffline( int timeOffline ) 147 { 148 this.timeOffline = timeOffline; 149 } 150 151 152 @Override 153 public Referral getReplicatedContexts() 154 { 155 return replicatedContexts; 156 } 157 158 159 160 /** 161 * {@inheritDoc} 162 */ 163 @Override 164 public void addReplicatedContexts( String replicatedContext ) 165 { 166 replicatedContexts.addLdapUrl( replicatedContext ); 167 } 168}