View Javadoc

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  package org.apache.directory.mitosis.operation;
21  
22  
23  import org.apache.directory.mitosis.common.CSN;
24  import org.apache.directory.mitosis.common.CSNVector;
25  import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
26  import org.apache.directory.mitosis.store.ReplicationLogIterator;
27  import org.apache.directory.mitosis.store.ReplicationStore;
28  import org.apache.directory.server.core.CoreSession;
29  import org.apache.directory.server.core.DirectoryService;
30  import org.apache.directory.server.core.partition.PartitionNexus;
31  import org.apache.directory.server.schema.registries.Registries;
32  
33  import javax.naming.Name;
34  
35  import java.util.ArrayList;
36  import java.util.List;
37  import java.util.Set;
38  import java.util.UUID;
39  
40  
41  /**
42   * An {@link Operation} that contains other {@link Operation}s.
43   *
44   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
45   */
46  public class CompositeOperation extends Operation
47  {
48      /**
49       * Declares the Serial Version Uid.
50       *
51       * @see <a
52       *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
53       *      Declare Serial Version Uid</a>
54       */
55      private static final long serialVersionUID = 6252675003841951356L;
56  
57      
58      /**
59       * A dummy replication store, used 
60       */
61      private static final ReplicationStore DUMMY_STORE = new ReplicationStore()
62      {
63  
64          public void open( DirectoryService directoryService, ReplicationConfiguration cfg )
65          {
66          }
67  
68  
69          public void close()
70          {
71          }
72  
73  
74          public String getReplicaId()
75          {
76              return null;
77          }
78  
79  
80          public Set<String> getKnownReplicaIds()
81          {
82              return null;
83          }
84  
85  
86          public Name getDN( UUID uuid )
87          {
88              return null;
89          }
90  
91  
92          public boolean putUUID( UUID uuid, Name dn )
93          {
94              return false;
95          }
96  
97  
98          public boolean removeUUID( UUID uuid )
99          {
100             return false;
101         }
102 
103 
104         public void putLog( Operation operation )
105         {
106         }
107 
108 
109         public ReplicationLogIterator getLogs( CSN fromCSN, boolean inclusive )
110         {
111             return null;
112         }
113 
114 
115         public ReplicationLogIterator getLogs( CSNVector updateVector, boolean inclusive )
116         {
117             return null;
118         }
119 
120 
121         public int removeLogs( CSN toCSN, boolean inclusive )
122         {
123             return 0;
124         }
125 
126 
127         public int getLogSize()
128         {
129             return 0;
130         }
131 
132 
133         public int getLogSize( String replicaId )
134         {
135             return 0;
136         }
137 
138 
139         public CSNVector getUpdateVector()
140         {
141             return null;
142         }
143 
144 
145         public CSNVector getPurgeVector()
146         {
147             return null;
148         }
149     };
150 
151     private final List<Operation> children = new ArrayList<Operation>();
152 
153 
154     /**
155      * Creates a new instance of CompositeOperation. This should not be called
156      * outside of this package.
157      *
158      * @param registries The server registries
159      */
160     /* No qualifier */ CompositeOperation( Registries registries )
161     {
162         super( registries, OperationType.COMPOSITE_OPERATION );
163     }
164 
165 
166     /**
167      * Creates a new instance of CompositeOperation.
168      *
169      * @param registries The server registries
170      * @param csn the operation CSN
171      */
172     public CompositeOperation( Registries registries, CSN csn )
173     {
174         super( registries, OperationType.COMPOSITE_OPERATION, csn );
175     }
176 
177 
178     /**
179      * Add a new operation to this composite operation
180      *
181      * @param op The added operation
182      */
183     public void add( Operation op )
184     {
185         assert op != null;
186         assert op.getCSN().equals( csn );
187         
188         children.add( op );
189     }
190 
191 
192     /**
193      * Remove all the inner operations.
194      */
195     public void clear()
196     {
197         children.clear();
198     }
199 
200 
201     /**
202      * Apply the replication on each internal operation.
203      * 
204      * @param nexus the partition on which the modification will be done
205      * @param store the replication store
206      * @param coreSession the current session
207      */
208     protected void execute0( PartitionNexus nexus, ReplicationStore store, CoreSession coreSession ) 
209         throws Exception
210     {
211         for ( Operation op : children )
212         {
213             op.execute( nexus, DUMMY_STORE, coreSession );
214         }
215     }
216     
217     
218     /**
219      * @return the number of included operations
220      */
221     public int size()
222     {
223         return children.size();
224     }
225     
226     
227     /**
228      * @return The list of all included operations
229      */
230     public List<Operation> getChildren()
231     {
232         return children;
233     }
234 
235 
236     /**
237      * @see Object#toString()
238      */
239     public String toString()
240     {
241         return children.toString();
242     }
243 }