/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
* Portions Copyright 2013 ForgeRock AS.
*/
/**
* This message is used by LDAP server when they first connect.
* to a replication server to let them know who they are and what is their state
* (their RUV)
*/
{
private int maxReceiveQueue;
private int maxSendQueue;
private int maxReceiveDelay;
private int maxSendDelay;
private int windowSize;
/**
* The time in milliseconds between heartbeats from the replication
* server. Zero means heartbeats are off.
*/
/**
* Whether to continue using SSL to encrypt messages after the start
* messages have been exchanged.
*/
private boolean sslEncryption;
/**
* Creates a new ServerStartMsg. This message is to be sent by an LDAP
* Server after being connected to a replication server for a given
* replication domain.
*
* @param serverId2 The serverId of the server for which the ServerStartMsg
* is created.
* @param serverURL directory server URL
* @param baseDn The base DN.
* @param windowSize The window size used by this server.
* @param heartbeatInterval The requested heartbeat interval.
* @param serverState The state of this server.
* @param generationId The generationId for this server.
* @param sslEncryption Whether to continue using SSL to encrypt messages
* after the start messages have been exchanged.
* @param groupId The group id of the DS for this DN
*/
long generationId, boolean sslEncryption,
byte groupId)
{
this.maxReceiveDelay = 0;
this.maxReceiveQueue = 0;
this.maxSendDelay = 0;
this.maxSendQueue = 0;
this.windowSize = windowSize;
this.heartbeatInterval = heartbeatInterval;
this.sslEncryption = sslEncryption;
this.serverState = serverState;
}
/**
* Creates a new ServerStartMsg from its encoded form.
*
* @param in The byte array containing the encoded form of the
* ServerStartMsg.
* @throws DataFormatException If the byte array does not contain a valid
* encoded form of the ServerStartMsg.
*/
{
byte[] allowedPduTypes = new byte[1];
try
{
/* first bytes are the header */
int pos = headerLength;
/*
* read the dn
* first calculate the length then construct the string
*/
/*
* read the ServerId
*/
/*
* read the ServerURL
*/
/*
* read the maxReceiveDelay
*/
/*
* read the maxReceiveQueue
*/
/*
* read the maxSendDelay
*/
/*
* read the maxSendQueue
*/
/*
* read the windowSize
*/
/*
* read the heartbeatInterval
*/
/*
* read the sslEncryption setting
*/
// Read the ServerState
// Caution: ServerState MUST be the last field. Because ServerState can
// contain null character (string termination of sererid string ..) it
// cannot be decoded using getNextLength() like the other fields. The
// only way is to rely on the end of the input buffer : and that forces
// the ServerState to be the last. This should be changed and we want to
// have more than one ServerState field.
} catch (UnsupportedEncodingException e)
{
throw new DataFormatException("UTF-8 is not supported by this jvm.");
}
}
/**
* Get the ServerID from the message.
* @return the server ID
*/
public int getServerId()
{
return serverId;
}
/**
* get the Server URL from the message.
* @return the server URL
*/
{
return serverURL;
}
/**
* Get the baseDn.
* @return Returns the baseDn.
*/
{
return baseDn;
}
/**
* Get the maxReceiveDelay.
* @return Returns the maxReceiveDelay.
*/
public int getMaxReceiveDelay()
{
return maxReceiveDelay;
}
/**
* Get the maxReceiveQueue.
* @return Returns the maxReceiveQueue.
*/
public int getMaxReceiveQueue()
{
return maxReceiveQueue;
}
/**
* Get the maxSendDelay.
* @return Returns the maxSendDelay.
*/
public int getMaxSendDelay()
{
return maxSendDelay;
}
/**
* Get the maxSendQueue.
* @return Returns the maxSendQueue.
*/
public int getMaxSendQueue()
{
return maxSendQueue;
}
/**
* Get the ServerState.
* @return The ServerState.
*/
{
return serverState;
}
/**
* {@inheritDoc}
*/
{
try {
byte[] byteMaxRecvDelay =
byte[] byteMaxRecvQueue =
byte[] byteMaxSendDelay =
byte[] byteMaxSendQueue =
byte[] byteWindowSize =
byte[] byteHeartbeatInterval =
byte[] byteSSLEncryption =
/* encode the header in a byte[] large enough to also contain the mods */
int pos = headerLength;
return resultByteArray;
}
catch (UnsupportedEncodingException e)
{
return null;
}
}
/**
* Get the window size for the ldap server that created the message.
*
* @return The window size for the ldap server that created the message.
*/
public int getWindowSize()
{
return windowSize;
}
/**
* Get the heartbeat interval requested by the ldap server that created the
* message.
*
* @return The heartbeat interval requested by the ldap server that created
* the message.
*/
public long getHeartbeatInterval()
{
return heartbeatInterval;
}
/**
* Get the SSL encryption value for the ldap server that created the
* message.
*
* @return The SSL encryption value for the ldap server that created the
* message.
*/
public boolean getSSLEncryption()
{
return sslEncryption;
}
/**
* {@inheritDoc}
*/
{
return "ServerStartMsg content: " +
"\nprotocolVersion: " + protocolVersion +
"\ngenerationId: " + generationId +
"\ngroupId: " + groupId +
"\nbaseDn: " + baseDn +
"\nheartbeatInterval: " + heartbeatInterval +
"\nmaxReceiveDelay: " + maxReceiveDelay +
"\nmaxReceiveQueue: " + maxReceiveQueue +
"\nmaxSendDelay: " + maxSendDelay +
"\nmaxSendQueue: " + maxSendQueue +
"\nserverId: " + serverId +
"\nserverState: " + serverState +
"\nserverURL: " + serverURL +
"\nsslEncryption: " + sslEncryption +
"\nwindowSize: " + windowSize;
}
}