directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r373297 - in /directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message: ExtendedRequestImpl.java ExtendedResponseImpl.java extended/GracefulDisconnect.java
Date Sun, 29 Jan 2006 09:19:17 GMT
Author: akarasulu
Date: Sun Jan 29 01:19:13 2006
New Revision: 373297

URL: http://svn.apache.org/viewcvs?rev=373297&view=rev
Log:
adding the JNDI compatible representations of codec objects for graceful shutdowns

Added:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java
Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedResponseImpl.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedRequestImpl.java?rev=373297&r1=373296&r2=373297&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
Sun Jan 29 01:19:13 2006
@@ -36,8 +36,8 @@
     /** Extended request's Object Identifier or <b>requestName</b> */
     private String oid;
     /** Extended request's payload or <b>requestValue</b> */
-    private byte [] payload;
-    private ResultResponse response;
+    protected byte [] payload;
+    protected ResultResponse response;
 
 
     // -----------------------------------------------------------------------

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedResponseImpl.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedResponseImpl.java?rev=373297&r1=373296&r2=373297&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedResponseImpl.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/ExtendedResponseImpl.java
Sun Jan 29 01:19:13 2006
@@ -33,7 +33,7 @@
     /** Object identifier for the extended response */
     private String oid ;
     /** Values encoded in the extended response payload */
-    private byte [] value ;
+    protected byte [] value ;
 
 
     // ------------------------------------------------------------------------

Added: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java?rev=373297&view=auto
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java
(added)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java
Sun Jan 29 01:19:13 2006
@@ -0,0 +1,225 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.common.message.extended;
+
+
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.ldap.common.codec.extended.operations.GracefulDisconnectContainer;
+import org.apache.ldap.common.codec.util.LdapURL;
+import org.apache.ldap.common.codec.util.LdapURLEncodingException;
+import org.apache.ldap.common.message.ExtendedResponseImpl;
+import org.apache.ldap.common.message.Referral;
+import org.apache.ldap.common.message.ReferralImpl;
+import org.apache.ldap.common.message.ResultCodeEnum;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An unsolicited notification, extended response, intended for notifying 
+ * clients of upcoming disconnection due to intended service windows.  
+ * Unlike the {@see NoticeOfDisconnect} this response contains additional 
+ * information about the amount of time the server will be offline and 
+ * exactly when it intends to shutdown.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class GracefulDisconnect extends ExtendedResponseImpl
+{
+    private static final long serialVersionUID = -4682291068700593492L;
+    public static final String OID = "1.2.6.1.4.1.18060.1.1.1.100.5";
+    private static final Logger log = LoggerFactory.getLogger( GracefulDisconnect.class );
+    
+    /** offline Time after disconnection */
+    private int timeOffline;
+
+    /** Delay before disconnection */
+    private int delay;
+    
+    /** String based LDAP URL that may be followed for replicated namingContexts */
+    private Referral replicatedContexts = new ReferralImpl();
+
+
+    public GracefulDisconnect( int timeOffline, int delay )
+    {
+        super( 0 );
+        this.timeOffline = timeOffline;
+        this.delay = delay;
+        
+        StringBuffer buf = new StringBuffer();
+        buf.append( "The server will disconnect and will be unavailable for " ).append( timeOffline
);
+        buf.append( " minutes in " ).append( delay ).append( " seconds." );
+        
+        super.getLdapResult().setErrorMessage( buf.toString() );
+        super.getLdapResult().setMatchedDn( "" );
+        super.getLdapResult().setResultCode( ResultCodeEnum.UNAVAILABLE );
+    }
+    
+    
+    private void encodeResponse()
+    {
+        org.apache.ldap.common.codec.extended.operations.GracefulDisconnect codec =
+            new org.apache.ldap.common.codec.extended.operations.GracefulDisconnect();
+        codec.setTimeOffline( this.timeOffline );
+        codec.setDelay( this.delay );
+        Iterator contexts = this.replicatedContexts.getLdapUrls().iterator();
+        while ( contexts.hasNext() )
+        {
+            String urlstr = ( String ) contexts.next();
+            LdapURL url = null;
+            try
+            {
+                url = new LdapURL( urlstr );
+            }
+            catch ( LdapURLEncodingException e )
+            {
+                log.error( "Failed while parsing LDAP url " + urlstr, e );
+                continue;
+            } 
+            codec.addReplicatedContexts( url );
+        }
+        
+        try
+        {
+            super.value = codec.encode( null ).array();
+        }
+        catch ( EncoderException e )
+        {
+            log.error( "Failed to encode message value.", e );
+        }
+    }
+    
+    
+    // ------------------------------------------------------------------------
+    // ExtendedResponse Interface Method Implementations
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Gets the reponse OID specific encoded response values.
+     *
+     * @return the response specific encoded response values.
+     */
+    public byte [] getResponse()
+    {
+        if ( value == null )
+        {
+            encodeResponse();
+        }
+        return value;
+    }
+
+
+    /**
+     * Sets the reponse OID specific encoded response values.
+     *
+     * @param value the response specific encoded response values.
+     */
+    public void setResponse( byte [] value )
+    {
+        ByteBuffer bb = ByteBuffer.wrap( value );
+        GracefulDisconnectContainer container = new GracefulDisconnectContainer();
+        Asn1Decoder decoder = new Asn1Decoder();
+        try
+        {
+            decoder.decode( bb, container );
+        }
+        catch ( DecoderException e )
+        {
+            log.error( "Failed while decoding response", e );
+        }
+        org.apache.ldap.common.codec.extended.operations.GracefulDisconnect codec =
+            container.getGracefulDisconnect();
+        this.delay = codec.getDelay();
+        this.timeOffline = codec.getTimeOffline();
+        List contexts = codec.getReplicatedContexts();
+        for ( int ii = 0; ii < contexts.size(); ii++ )
+        {
+            LdapURL url = ( LdapURL ) contexts.get( ii );
+            replicatedContexts.addLdapUrl( url.toString() );
+        }
+        
+        this.value = value;
+    }
+
+
+    /**
+     * Gets the OID uniquely identifying this extended response (a.k.a. its
+     * name).
+     *
+     * @return the OID of the extended response type.
+     */
+    public String getResponseName()
+    {
+        return OID;
+    }
+
+
+    /**
+     * Sets the OID uniquely identifying this extended response (a.k.a. its
+     * name).
+     *
+     * @param oid the OID of the extended response type.
+     */
+    public void setResponseName( String oid )
+    {
+        throw new UnsupportedOperationException( "the OID is fixed: " + OID );
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Parameters of the Extended Response Value
+    // -----------------------------------------------------------------------
+
+
+    public void setDelay(int delay)
+    {
+        this.delay = delay;
+    }
+
+
+    public void setTimeOffline(int timeOffline)
+    {
+        this.timeOffline = timeOffline;
+    }
+
+    
+    public int getDelay()
+    {
+        return delay;
+    }
+
+
+    public int getTimeOffline()
+    {
+        return timeOffline;
+    }
+
+
+    public Referral getReplicatedContexts()
+    {
+        return replicatedContexts;
+    }
+}



Mime
View raw message