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 * http://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.server.core.api.interceptor.context; 021 022 023import org.apache.directory.api.ldap.model.entry.Entry; 024import org.apache.directory.api.ldap.model.name.Dn; 025import org.apache.directory.server.core.api.CoreSession; 026import org.apache.directory.server.core.api.changelog.ChangeLogEvent; 027import org.apache.directory.server.core.api.changelog.LogChange; 028 029 030/** 031 * An abstract base class used by all change inducing operations. 032 * 033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 034 */ 035public abstract class AbstractChangeOperationContext extends AbstractOperationContext implements ChangeOperationContext 036{ 037 /** The ChangeLog event */ 038 private ChangeLogEvent changeLogEvent; 039 040 /** The flag used to tell the server to store the changes into the changeLog */ 041 protected LogChange logChange; 042 043 /** The modified Entry as it will be stored into the backend */ 044 protected Entry modifiedEntry; 045 046 /** flag to indicate if this context is carrying a replicated entry */ 047 private boolean replEvent; 048 049 /** the rid present in the cookie received from a replication consumer */ 050 private int rid = -1; // default value, an invalid rid 051 052 /** a flag to indicate when we don't want a replication event to be generated after this operation */ 053 private boolean generateNoReplEvt; 054 055 /** 056 * flag to tell if this context needs to be sent to the event interceptor manually 057 * This is used only internally where certain modifications do not go through event 058 * interceptor. 059 */ 060 private boolean pushToEvtInterceptor; 061 062 /** 063 * 064 * Creates a new instance of AbstractChangeOperationContext. 065 * 066 * @param session The session to use 067 */ 068 public AbstractChangeOperationContext( CoreSession session ) 069 { 070 super( session ); 071 } 072 073 074 /** 075 * 076 * Creates a new instance of AbstractChangeOperationContext. 077 * 078 * @param session The session to use 079 * @param dn The Dn for the entry on which the change is applied 080 */ 081 public AbstractChangeOperationContext( CoreSession session, Dn dn ) 082 { 083 super( session, dn ); 084 } 085 086 087 /** 088 * @return the modifiedEntry 089 */ 090 public Entry getModifiedEntry() 091 { 092 return modifiedEntry; 093 } 094 095 096 /** 097 * @param modifiedEntry the modifiedEntry to set 098 */ 099 public void setModifiedEntry( Entry modifiedEntry ) 100 { 101 this.modifiedEntry = modifiedEntry; 102 } 103 104 105 /** 106 * @see org.apache.directory.server.core.api.interceptor.context.ChangeOperationContext#getChangeLogEvent() 107 */ 108 @Override 109 public ChangeLogEvent getChangeLogEvent() 110 { 111 return changeLogEvent; 112 } 113 114 115 public void setChangeLogEvent( ChangeLogEvent changeLogEvent ) 116 { 117 this.changeLogEvent = changeLogEvent; 118 } 119 120 121 /** 122 * {@inheritDoc} 123 */ 124 @Override 125 public void setLogChange( LogChange logChange ) 126 { 127 this.logChange = logChange; 128 } 129 130 131 /** 132 * {@inheritDoc} 133 */ 134 @Override 135 public boolean isLogChange() 136 { 137 return logChange != LogChange.FALSE; 138 } 139 140 141 /** 142 * @return true if this context is containing a replication event 143 */ 144 public boolean isReplEvent() 145 { 146 return replEvent; 147 } 148 149 150 /** 151 * @param replEvent mark the context as containing a replication event 152 */ 153 public void setReplEvent( boolean replEvent ) 154 { 155 this.replEvent = replEvent; 156 } 157 158 159 /** 160 * @return the replica ID received from a consumer 161 */ 162 public int getRid() 163 { 164 return rid; 165 } 166 167 168 /** 169 * sets the replica ID received from a consumer 170 * 171 * @param rid The replica ID 172 */ 173 public void setRid( int rid ) 174 { 175 this.rid = rid; 176 } 177 178 179 /** 180 * @return true if a replication event shouldn't be generated for the changes 181 * done using this operation context, false otherwise 182 */ 183 public boolean isGenerateNoReplEvt() 184 { 185 return generateNoReplEvt; 186 } 187 188 189 /** 190 * sets whether or not to generate replication event messages by after an operation 191 * using this operation context completes 192 * 193 * @param generateNoReplEvt <tt>true</tt> if replication events are to be generated 194 */ 195 public void setGenerateNoReplEvt( boolean generateNoReplEvt ) 196 { 197 this.generateNoReplEvt = generateNoReplEvt; 198 } 199 200 201 /** 202 * @return true if this context needs to be pushed to the event interceptor from nexus 203 */ 204 public boolean isPushToEvtInterceptor() 205 { 206 return pushToEvtInterceptor; 207 } 208 209 210 /** 211 * sets if this context needs to be pushed to the event interceptor from nexus 212 * 213 * @param pushToEvtIntercptor <tt>true</tt> if the context needs to be pushed to the event Interceptor 214 */ 215 public void setPushToEvtInterceptor( boolean pushToEvtIntercptor ) 216 { 217 this.pushToEvtInterceptor = pushToEvtIntercptor; 218 } 219}