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 * https://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.AbstractExtendedResponse; 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 AbstractExtendedResponse 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 * Sets the OID uniquely identifying this extended response (a.k.a. its 085 * name). 086 * 087 * @param oid the OID of the extended response type. 088 */ 089 @Override 090 public void setResponseName( String oid ) 091 { 092 throw new UnsupportedOperationException( I18n.err( I18n.ERR_13504_FIX_OID, EXTENSION_OID ) ); 093 } 094 095 096 // ----------------------------------------------------------------------- 097 // Parameters of the Extended Response Value 098 // ----------------------------------------------------------------------- 099 /** 100 * {@inheritDoc} 101 */ 102 @Override 103 public int getDelay() 104 { 105 return delay; 106 } 107 108 109 /** 110 * {@inheritDoc} 111 */ 112 @Override 113 public void setDelay( int delay ) 114 { 115 this.delay = delay; 116 } 117 118 119 /** 120 * {@inheritDoc} 121 */ 122 @Override 123 public int getTimeOffline() 124 { 125 return timeOffline; 126 } 127 128 129 /** 130 * {@inheritDoc} 131 */ 132 @Override 133 public void setTimeOffline( int timeOffline ) 134 { 135 this.timeOffline = timeOffline; 136 } 137 138 139 /** 140 * {@inheritDoc} 141 */ 142 @Override 143 public Referral getReplicatedContexts() 144 { 145 return replicatedContexts; 146 } 147 148 149 150 /** 151 * {@inheritDoc} 152 */ 153 @Override 154 public void addReplicatedContexts( String replicatedContext ) 155 { 156 replicatedContexts.addLdapUrl( replicatedContext ); 157 } 158}