StartECLSessionMsg.java revision 5280
4501N/A/*
4501N/A * CDDL HEADER START
4501N/A *
4501N/A * The contents of this file are subject to the terms of the
4501N/A * Common Development and Distribution License, Version 1.0 only
4501N/A * (the "License"). You may not use this file except in compliance
4501N/A * with the License.
4501N/A *
4501N/A * You can obtain a copy of the license at
4501N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
4501N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
4501N/A * See the License for the specific language governing permissions
4501N/A * and limitations under the License.
4501N/A *
4501N/A * When distributing Covered Code, include this CDDL HEADER in each
4501N/A * file and include the License file at
4501N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
4501N/A * add the following below this CDDL HEADER, with the fields enclosed
4501N/A * by brackets "[]" replaced with your own identifying information:
4501N/A * Portions Copyright [yyyy] [name of copyright owner]
4501N/A *
4501N/A * CDDL HEADER END
4501N/A *
4501N/A *
5031N/A * Copyright 2009-2010 Sun Microsystems, Inc.
4501N/A */
4501N/Apackage org.opends.server.replication.protocol;
4501N/A
4501N/Aimport java.io.IOException;
4501N/Aimport java.io.UnsupportedEncodingException;
4501N/Aimport java.util.ArrayList;
4501N/Aimport java.util.zip.DataFormatException;
4501N/A
4501N/Aimport org.opends.server.replication.common.ChangeNumber;
4501N/A
4501N/A
4501N/A/**
4501N/A * This class specifies the parameters of a search request on the ECL.
4501N/A * It is used as an interface between the requestor (plugin part)
4501N/A * - either as an han
4501N/A */
4501N/Apublic class StartECLSessionMsg extends ReplicationMsg
4501N/A{
4501N/A
4501N/A /**
4501N/A * This specifies that the ECL is requested from a provided cookie value
4501N/A * defined as a MultiDomainServerState.
4501N/A */
4501N/A public final static short REQUEST_TYPE_FROM_COOKIE = 0;
4501N/A
4501N/A /**
4501N/A * This specifies that the ECL is requested from a provided interval
4501N/A * of change numbers (as defined by draft-good-ldap-changelog [CHANGELOG]
4501N/A * and NOT replication change numbers).
4501N/A * TODO: not yet implemented
4501N/A */
4501N/A public final static short REQUEST_TYPE_FROM_DRAFT_CHANGE_NUMBER = 1;
4501N/A
4501N/A /**
4501N/A * This specifies that the ECL is requested ony for the entry that have
4501N/A * a repl change number matching the provided one.
4501N/A * TODO: not yet implemented
4501N/A */
4501N/A public final static short REQUEST_TYPE_EQUALS_REPL_CHANGE_NUMBER = 2;
4501N/A
4501N/A
4501N/A
4501N/A /**
4501N/A * This specifies that the request on the ECL is a PERSISTENT search
4501N/A * with changesOnly = false.
4501N/A */
4501N/A public final static short PERSISTENT = 0;
4501N/A
4501N/A /**
4501N/A * This specifies that the request on the ECL is a NOT a PERSISTENT search.
4501N/A */
4501N/A public final static short NON_PERSISTENT = 1;
4501N/A
4501N/A /**
4501N/A * This specifies that the request on the ECL is a PERSISTENT search
5280N/A * with changesOnly = true.
4501N/A */
5031N/A public final static short PERSISTENT_CHANGES_ONLY = 2;
4501N/A
4501N/A
4501N/A
4501N/A // The type of request as defined by REQUEST_TYPE_...
4501N/A private short eclRequestType;
4501N/A
4501N/A // When eclRequestType = FROM_COOKIE,
4501N/A // specifies the provided cookie value.
4501N/A private String crossDomainServerState = "";
4501N/A
4501N/A // When eclRequestType = FROM_CHANGE_NUMBER,
4501N/A // specifies the provided change number first and last - [CHANGELOG]
4501N/A private int firstDraftChangeNumber = -1;
4501N/A private int lastDraftChangeNumber = -1;
4501N/A
4501N/A // When eclRequestType = EQUALS_REPL_CHANGE_NUMBER,
4501N/A // specifies the provided replication change number.
4501N/A private ChangeNumber changeNumber;
4501N/A
4501N/A // Specifies whether the search is persistent and changesOnly
4641N/A private short isPersistent = NON_PERSISTENT;
4501N/A
4501N/A // A string helping debuging and tracing the client operation related when
4501N/A // processing, on the RS side, a request on the ECL.
4501N/A private String operationId = "";
4501N/A
4501N/A // Excluded domains
4501N/A private ArrayList<String> excludedServiceIDs = new ArrayList<String>();
4501N/A
4501N/A /**
4501N/A * Creates a new StartSessionMsg message from its encoded form.
4501N/A *
4501N/A * @param in The byte array containing the encoded form of the message.
4501N/A * @throws java.util.zip.DataFormatException If the byte array does not
4501N/A * contain a valid encoded form of the message.
4501N/A */
4501N/A public StartECLSessionMsg(byte[] in) throws DataFormatException
4501N/A {
4501N/A /*
4501N/A * The message is stored in the form:
4501N/A * <message type><status><assured flag><assured mode><safe data level>
4501N/A * <list of referrals urls>
4501N/A * (each referral url terminates with 0)
4501N/A */
4501N/A
4501N/A try
4501N/A {
4501N/A /* first bytes are the header */
4501N/A int pos = 0;
4501N/A
4501N/A /* first byte is the type */
4501N/A if (in.length < 1 || in[pos++] != MSG_TYPE_START_ECL_SESSION)
4501N/A {
4501N/A throw new DataFormatException(
4501N/A "Input is not a valid " + this.getClass().getCanonicalName());
4501N/A }
4501N/A
4501N/A // start mode
4501N/A int length = getNextLength(in, pos);
4501N/A eclRequestType = Short.valueOf(new String(in, pos, length, "UTF-8"));
4501N/A pos += length +1;
4501N/A
4501N/A // sequenceNumber
4501N/A length = getNextLength(in, pos);
4501N/A firstDraftChangeNumber =
4501N/A Integer.valueOf(new String(in, pos, length, "UTF-8"));
4501N/A pos += length +1;
4501N/A
4501N/A // stopSequenceNumber
4501N/A length = getNextLength(in, pos);
4501N/A lastDraftChangeNumber =
4501N/A Integer.valueOf(new String(in, pos, length, "UTF-8"));
4501N/A pos += length +1;
4501N/A
4501N/A // replication changeNumber
4501N/A length = getNextLength(in, pos);
4501N/A String changenumberStr = new String(in, pos, length, "UTF-8");
4501N/A pos += length + 1;
4501N/A changeNumber = new ChangeNumber(changenumberStr);
4501N/A
4501N/A // persistentSearch mode
4501N/A length = getNextLength(in, pos);
4501N/A isPersistent = Short.valueOf(new String(in, pos, length, "UTF-8"));
4501N/A pos += length + 1;
4501N/A
4501N/A // generalized state
4501N/A length = getNextLength(in, pos);
4501N/A crossDomainServerState = new String(in, pos, length, "UTF-8");
4501N/A pos += length + 1;
4501N/A
4501N/A // operation id
4501N/A length = getNextLength(in, pos);
4501N/A operationId = new String(in, pos, length, "UTF-8");
4501N/A pos += length + 1;
4501N/A
4501N/A // excluded DN
4501N/A length = getNextLength(in, pos);
4501N/A String excludedDNsString = new String(in, pos, length, "UTF-8");
4501N/A if (excludedDNsString.length()>0)
4501N/A {
4501N/A String[] excludedDNsStr = excludedDNsString.split(";");
4501N/A for (String excludedDNStr : excludedDNsStr)
4501N/A {
4501N/A this.excludedServiceIDs.add(excludedDNStr);
4501N/A }
4501N/A }
4501N/A pos += length + 1;
4501N/A
4501N/A } catch (UnsupportedEncodingException e)
4501N/A {
4501N/A throw new DataFormatException("UTF-8 is not supported by this jvm.");
4501N/A } catch (IllegalArgumentException e)
4501N/A {
4501N/A throw new DataFormatException(e.getMessage());
4501N/A }
4501N/A }
4501N/A
4501N/A /**
4501N/A * Creates a new StartSessionMsg message with the given required parameters.
4501N/A */
4501N/A public StartECLSessionMsg()
4501N/A {
4641N/A eclRequestType = REQUEST_TYPE_FROM_COOKIE;
4641N/A crossDomainServerState = "";
4641N/A firstDraftChangeNumber = -1;
4641N/A lastDraftChangeNumber = -1;
4802N/A changeNumber = new ChangeNumber(0,0,0);
4641N/A isPersistent = NON_PERSISTENT;
4641N/A operationId = "-1";
4641N/A excludedServiceIDs = new ArrayList<String>();
4501N/A }
4501N/A
4501N/A /**
4501N/A * {@inheritDoc}
4501N/A */
4501N/A @Override
4501N/A public byte[] getBytes()
4501N/A {
4501N/A String excludedSIDsString = new String();
4501N/A for (String excludedServiceID : excludedServiceIDs)
4501N/A {
4501N/A excludedSIDsString = excludedSIDsString.concat(excludedServiceID+";");
4501N/A }
4501N/A
4501N/A try
4501N/A {
4501N/A byte[] byteMode =
4501N/A Short.toString(eclRequestType).getBytes("UTF-8");
4501N/A byte[] byteSequenceNumber =
4501N/A String.valueOf(firstDraftChangeNumber).getBytes("UTF-8");
4501N/A byte[] byteStopSequenceNumber =
4501N/A String.valueOf(lastDraftChangeNumber).getBytes("UTF-8");
4501N/A byte[] byteChangeNumber =
4501N/A changeNumber.toString().getBytes("UTF-8");
4501N/A byte[] bytePsearch =
4501N/A Short.toString(isPersistent).getBytes();
4501N/A byte[] byteGeneralizedState =
4501N/A String.valueOf(crossDomainServerState).getBytes("UTF-8");
4501N/A byte[] byteOperationId =
4501N/A String.valueOf(operationId).getBytes("UTF-8");
4501N/A byte[] byteExcludedDNs =
4501N/A String.valueOf(excludedSIDsString).getBytes("UTF-8");
4501N/A
4501N/A int length =
4501N/A byteMode.length + 1 +
4501N/A byteSequenceNumber.length + 1 +
4501N/A byteStopSequenceNumber.length + 1 +
4501N/A byteChangeNumber.length + 1 +
4501N/A bytePsearch.length + 1 +
4501N/A byteGeneralizedState.length + 1 +
4501N/A byteOperationId.length + 1 +
4501N/A byteExcludedDNs.length + 1 +
4501N/A 1;
4501N/A
4501N/A byte[] resultByteArray = new byte[length];
4501N/A int pos = 0;
4501N/A resultByteArray[pos++] = MSG_TYPE_START_ECL_SESSION;
4501N/A pos = addByteArray(byteMode, resultByteArray, pos);
4501N/A pos = addByteArray(byteSequenceNumber, resultByteArray, pos);
4501N/A pos = addByteArray(byteStopSequenceNumber, resultByteArray, pos);
4501N/A pos = addByteArray(byteChangeNumber, resultByteArray, pos);
4501N/A pos = addByteArray(bytePsearch, resultByteArray, pos);
4501N/A pos = addByteArray(byteGeneralizedState, resultByteArray, pos);
4501N/A pos = addByteArray(byteOperationId, resultByteArray, pos);
4501N/A pos = addByteArray(byteExcludedDNs, resultByteArray, pos);
4501N/A return resultByteArray;
4501N/A
4501N/A } catch (IOException e)
4501N/A {
4501N/A // never happens
4501N/A return null;
4501N/A }
4501N/A }
4501N/A
4501N/A
4501N/A /**
4501N/A * {@inheritDoc}
4501N/A */
4501N/A @Override
4501N/A public String toString()
4501N/A {
4501N/A return (this.getClass().getCanonicalName() + " [" +
4501N/A " requestType="+ eclRequestType +
4501N/A " persistentSearch=" + isPersistent +
4501N/A " changeNumber=" + changeNumber +
4501N/A " firstDraftChangeNumber=" + firstDraftChangeNumber +
4501N/A " lastDraftChangeNumber=" + lastDraftChangeNumber +
4501N/A " generalizedState=" + crossDomainServerState +
4501N/A " operationId=" + operationId +
4501N/A " excludedDNs=" + excludedServiceIDs + "]");
4501N/A }
4501N/A
4501N/A /**
4501N/A * Getter on the changer number start.
4501N/A * @return the changer number start.
4501N/A */
4501N/A public int getFirstDraftChangeNumber()
4501N/A {
4501N/A return firstDraftChangeNumber;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Getter on the changer number stop.
4501N/A * @return the change number stop.
4501N/A */
4501N/A public int getLastDraftChangeNumber()
4501N/A {
4501N/A return lastDraftChangeNumber;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Setter on the first changer number (as defined by [CHANGELOG]).
4501N/A * @param firstDraftChangeNumber the provided first change number.
4501N/A */
4501N/A public void setFirstDraftChangeNumber(int firstDraftChangeNumber)
4501N/A {
4501N/A this.firstDraftChangeNumber = firstDraftChangeNumber;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Setter on the last changer number (as defined by [CHANGELOG]).
4501N/A * @param lastDraftChangeNumber the provided last change number.
4501N/A */
4501N/A public void setLastDraftChangeNumber(int lastDraftChangeNumber)
4501N/A {
4501N/A this.lastDraftChangeNumber = lastDraftChangeNumber;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Getter on the replication change number.
4501N/A * @return the replication change number.
4501N/A */
4501N/A public ChangeNumber getChangeNumber()
4501N/A {
4501N/A return changeNumber;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Setter on the replication change number.
4501N/A * @param changeNumber the provided replication change number.
4501N/A */
4501N/A public void setChangeNumber(ChangeNumber changeNumber)
4501N/A {
4501N/A this.changeNumber = changeNumber;
4501N/A }
4501N/A /**
4501N/A * Getter on the type of request.
4501N/A * @return the type of request.
4501N/A */
4501N/A public short getECLRequestType()
4501N/A {
4501N/A return eclRequestType;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Setter on the type of request.
4501N/A * @param eclRequestType the provided type of request.
4501N/A */
4501N/A public void setECLRequestType(short eclRequestType)
4501N/A {
4501N/A this.eclRequestType = eclRequestType;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Getter on the persistent property of the search request on the ECL.
4501N/A * @return the persistent property.
4501N/A */
4501N/A public short isPersistent()
4501N/A {
4501N/A return this.isPersistent;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Setter on the persistent property of the search request on the ECL.
4501N/A * @param isPersistent the provided persistent property.
4501N/A */
4501N/A public void setPersistent(short isPersistent)
4501N/A {
4501N/A this.isPersistent = isPersistent;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Getter of the cross domain server state.
4501N/A * @return the cross domain server state.
4501N/A */
4501N/A public String getCrossDomainServerState()
4501N/A {
4501N/A return this.crossDomainServerState;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Setter of the cross domain server state.
4501N/A * @param crossDomainServerState the provided cross domain server state.
4501N/A */
4501N/A public void setCrossDomainServerState(String crossDomainServerState)
4501N/A {
4501N/A this.crossDomainServerState = crossDomainServerState;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Setter of the operation id.
4501N/A * @param operationId The provided opration id.
4501N/A */
4501N/A public void setOperationId(String operationId)
4501N/A {
4501N/A this.operationId = operationId;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Getter on the operation id.
4501N/A * @return the operation id.
4501N/A */
4501N/A public String getOperationId()
4501N/A {
4501N/A return this.operationId;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Getter on the list of excluded ServiceIDs.
4501N/A * @return the list of excluded ServiceIDs.
4501N/A */
4501N/A public ArrayList<String> getExcludedServiceIDs()
4501N/A {
4501N/A return this.excludedServiceIDs;
4501N/A }
4501N/A
4501N/A /**
4501N/A * Setter on the list of excluded ServiceIDs.
4501N/A * @param excludedServiceIDs the provided list of excluded ServiceIDs.
4501N/A */
4501N/A public void setExcludedDNs(ArrayList<String> excludedServiceIDs)
4501N/A {
4501N/A this.excludedServiceIDs = excludedServiceIDs;
4501N/A }
4501N/A
4501N/A}