1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 21 package org.apache.directory.server.ldap.replication; 22 23 24 import org.apache.directory.api.ldap.model.constants.SchemaConstants; 25 import org.apache.directory.api.ldap.model.entry.Entry; 26 import org.apache.directory.api.ldap.model.exception.LdapException; 27 import org.apache.directory.api.ldap.model.message.controls.ChangeType; 28 import org.apache.directory.server.core.api.entry.ClonedServerEntry; 29 30 31 /** 32 * A place holder storing an Entry and the operation applied on it 33 * 34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 35 */ 36 public class ReplicaEventMessage 37 { 38 /** The message change type */ 39 private ChangeType changeType; 40 41 /** The entry */ 42 private Entry entry; 43 44 /** 45 * Create a new ReplicaEvent instance for a Add/Delete+Modify operation 46 * @param changeType The change type 47 * @param entry The entry 48 */ 49 public ReplicaEventMessage( ChangeType changeType, Entry entry ) 50 { 51 this.changeType = changeType; 52 53 if ( entry instanceof ClonedServerEntry ) 54 { 55 this.entry = ( ( ClonedServerEntry ) entry ).getClonedEntry(); 56 } 57 else 58 { 59 this.entry = entry; 60 } 61 } 62 63 64 /** 65 * @return The changeType 66 */ 67 public ChangeType getChangeType() 68 { 69 return changeType; 70 } 71 72 73 /** 74 * @return The stored Entry 75 */ 76 public Entry getEntry() 77 { 78 return entry; 79 } 80 81 82 /** 83 * checks if the event's CSN is older than the given CSN 84 * 85 * @param csn the CSN 86 * @return true if the event's CSN is older than the given CSN 87 * @throws LdapException if there are any extreme conditions like a null entry or missing entryCSN attribute. 88 */ 89 public boolean isEventOlderThan( String csn ) throws LdapException 90 { 91 if ( csn == null ) 92 { 93 return false; 94 } 95 96 String entryCsn = entry.get( SchemaConstants.ENTRY_CSN_AT ).getString(); 97 98 int i = entryCsn.compareTo( csn ); 99 100 return ( i <= 0 ); 101 } 102 }