PageRenderTime 35ms CodeModel.GetById 15ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/impl/concurrentmap/InitialState.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 75 lines | 51 code | 9 blank | 15 comment | 8 complexity | d098d6281ec8ba204a1662add9487ccf MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.impl.concurrentmap;
18
19import com.hazelcast.cluster.AbstractRemotelyProcessable;
20import com.hazelcast.impl.CMap;
21import com.hazelcast.impl.FactoryImpl;
22import com.hazelcast.query.Index;
23
24import java.io.DataInput;
25import java.io.DataOutput;
26import java.io.IOException;
27import java.util.ArrayList;
28import java.util.List;
29
30public class InitialState extends AbstractRemotelyProcessable {
31    List<MapState> lsMapStates = new ArrayList<MapState>();
32
33    public InitialState() {
34    }
35
36    public void createAndAddMapState(CMap cmap) {
37        MapState mapState = new MapState(cmap.getName());
38        Index[] indexes = cmap.getMapIndexService().getIndexesInOrder();
39        if (indexes != null) {
40            for (Index index : indexes) {
41                AddMapIndex mi = new AddMapIndex(cmap.getName(), index.getExpression(), index.isOrdered(), index.getAttributeIndex());
42                mapState.addMapIndex(mi);
43            }
44        }
45        lsMapStates.add(mapState);
46    }
47
48    public void process() {
49        FactoryImpl factory = getNode().factory;
50        if (factory.node.isActive()) {
51            for (MapState mapState : lsMapStates) {
52                CMap cmap = factory.node.concurrentMapManager.getOrCreateMap(mapState.name);
53                for (AddMapIndex mapIndex : mapState.lsMapIndexes) {
54                    cmap.addIndex(mapIndex.getExpression(), mapIndex.isOrdered(), mapIndex.getAttributeIndex());
55                }
56            }
57        }
58    }
59
60    public void writeData(DataOutput out) throws IOException {
61        out.writeInt(lsMapStates.size());
62        for (MapState mapState : lsMapStates) {
63            mapState.writeData(out);
64        }
65    }
66
67    public void readData(DataInput in) throws IOException {
68        int size = in.readInt();
69        for (int i = 0; i < size; i++) {
70            MapState mapState = new MapState();
71            mapState.readData(in);
72            lsMapStates.add(mapState);
73        }
74    }
75}