-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7232111
commit 14597aa
Showing
18 changed files
with
467 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...st/src/main/java/com/hazelcast/map/mapstore/writebehind/AbstractWriteBehindProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.map.mapstore.writebehind; | ||
|
||
import com.hazelcast.config.MapStoreConfig; | ||
import com.hazelcast.core.MapStore; | ||
import com.hazelcast.logging.ILogger; | ||
import com.hazelcast.map.MapContainer; | ||
import com.hazelcast.nio.serialization.Data; | ||
import com.hazelcast.nio.serialization.SerializationService; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Contains common fuctionallity which is required by a {@link WriteBehindProcessor} | ||
* | ||
* @param <T> the type of object to be placed in the {@link WriteBehindQueue} | ||
*/ | ||
abstract class AbstractWriteBehindProcessor<T> implements WriteBehindProcessor<T> { | ||
|
||
protected final int writeBatchSize; | ||
|
||
protected final boolean writeCoalescing; | ||
|
||
protected final ILogger logger; | ||
|
||
protected final MapStore mapStore; | ||
|
||
private final SerializationService serializationService; | ||
|
||
public AbstractWriteBehindProcessor(MapContainer mapContainer) { | ||
this.serializationService = mapContainer.getMapServiceContext().getNodeEngine().getSerializationService(); | ||
this.mapStore = mapContainer.getStore(); | ||
this.logger = mapContainer.getMapServiceContext().getNodeEngine().getLogger(DefaultWriteBehindProcessor.class); | ||
MapStoreConfig mapStoreConfig = mapContainer.getMapConfig().getMapStoreConfig(); | ||
this.writeBatchSize = mapStoreConfig.getWriteBatchSize(); | ||
this.writeCoalescing = mapStoreConfig.isWriteCoalescing(); | ||
} | ||
|
||
protected Object toObject(Object obj) { | ||
return serializationService.toObject(obj); | ||
} | ||
|
||
protected Data toData(Object obj) { | ||
return serializationService.toData(obj); | ||
} | ||
|
||
|
||
protected void sleepSeconds(long secs) { | ||
try { | ||
TimeUnit.SECONDS.sleep(secs); | ||
} catch (InterruptedException e) { | ||
logger.warning(e); | ||
} | ||
} | ||
|
||
/** | ||
* Used to group store operations. | ||
*/ | ||
protected enum StoreOperationType { | ||
|
||
DELETE { | ||
@Override | ||
boolean processSingle(Object key, Object value, MapStore mapStore) { | ||
mapStore.delete(key); | ||
return true; | ||
} | ||
|
||
@Override | ||
boolean processBatch(Map map, MapStore mapStore) { | ||
mapStore.deleteAll(map.keySet()); | ||
return true; | ||
} | ||
}, | ||
|
||
WRITE { | ||
@Override | ||
boolean processSingle(Object key, Object value, MapStore mapStore) { | ||
mapStore.store(key, value); | ||
return true; | ||
} | ||
|
||
@Override | ||
boolean processBatch(Map map, MapStore mapStore) { | ||
mapStore.storeAll(map); | ||
return true; | ||
} | ||
}; | ||
|
||
abstract boolean processSingle(Object key, Object value, MapStore mapStore); | ||
|
||
abstract boolean processBatch(Map map, MapStore mapStore); | ||
} | ||
} |
Oops, something went wrong.