Skip to content

Commit

Permalink
Reviewed JCache chapter.
Browse files Browse the repository at this point in the history
Conflicts:
	hazelcast-documentation/src/JCache.md
  • Loading branch information
Serdaro committed Oct 28, 2014
1 parent 6619b72 commit 81a7714
Show file tree
Hide file tree
Showing 12 changed files with 595 additions and 89 deletions.
172 changes: 93 additions & 79 deletions hazelcast-documentation/src/JCache.md

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions hazelcast-documentation/src/WhatsNew.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
### New Features
This section provides the new features introduced with Hazelcast 3.4 release.

- Back Pressure - ??? Please see [Back Pressure](#back-pressure).
- High Density for JCache - Please see [High Density for JCache](#high-density-for-jcache).
- Jetty Specific Session Replication - Please see [Jetty Based Web Session Replication](#jetty-based-web-session-replication).
- High Density for JCache: ??? Please see [High Density for JCache](#high-density-for-jcache).
- Back Pressure: ??? Please see [Back Pressure](#back-pressure).
- Jetty Specific Session Replication: ??? Please see [Jetty Based Web Session Replication](#jetty-based-web-session-replication).
- Hazelcast Configuration Import: ???



Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2008-2013, 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.cache;

import javax.cache.processor.EntryProcessor;

/**
* An invocable function that allows applications to perform compound operations
* on a {@link javax.cache.Cache.Entry} atomically, according the defined
* consistency of a {@link javax.cache.Cache}.
* <p>
* In difference to the normal {@link javax.cache.processor.EntryProcessor}
* implementations where a backup is done using sending the complete changed resulting
* object to the backup-partition, implementations of this sub-interface can create
* an additional {@link javax.cache.processor.EntryProcessor} instances that are send
* to the backup-partitions to apply logic which is either different from the owner
* partition (e.g. not sending emails) or in the simple case similar to the main
* operations. In the later case {@link #createBackupEntryProcessor()} can also return
* <pre>this</pre>.
*
* @param <K> the type of keys maintained by this cache
* @param <V> the type of cached values
* @param <T> the type of the return value
* @see javax.cache.processor.EntryProcessor
* @since 3.4
*/
public interface BackupAwareEntryProcessor<K, V, T>
extends EntryProcessor<K, V, T> {

/**
* Either creates a new, specialized {@link javax.cache.processor.EntryProcessor}
* to be executed on the backup-partition or returns <pre>this</pre> to execute
* the same processor remotely.
* <p>
* If null is returned the value is backed up using the normal value backup
* mechanism, non exception is thrown and the update is applied as expected.
*
* @return the backup-partition EntryProcessor
*/
EntryProcessor<K, V, T> createBackupEntryProcessor();

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* </pre>
* </p>
*
* @since 3.3.1
*/
public interface CacheStatistics {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
* If no selection exists, then the default behavior for selecting the internal provider type is based on
* which dependency found on classpath. Client and server provider classes are searched on classpath respectively.
* </p>
*
* @since 3.4
*/
public final class HazelcastCachingProvider
implements CachingProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* </code>
* </pre>
* </p>
*
* @since 3.3.1
*/
public class HazelcastExpiryPolicy implements ExpiryPolicy, IdentifiedDataSerializable, Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hazelcast.cache.impl;

import com.hazelcast.cache.impl.operation.CacheBackupEntryProcessorOperation;
import com.hazelcast.cache.impl.operation.CacheClearBackupOperation;
import com.hazelcast.cache.impl.operation.CacheClearOperation;
import com.hazelcast.cache.impl.operation.CacheClearOperationFactory;
Expand Down Expand Up @@ -92,8 +93,9 @@ public final class CacheDataSerializerHook
public static final short DESTROY_CACHE = 30;
public static final short CACHE_EVENT_DATA = 31;
public static final short CACHE_EVENT_DATA_SET = 32;
public static final short BACKUP_ENTRY_PROCESSOR = 33;

private static final int LEN = 33;
private static final int LEN = 34;

public int getFactoryId() {
return F_ID;
Expand Down Expand Up @@ -257,6 +259,12 @@ public IdentifiedDataSerializable createNew(Integer arg) {
return new CacheEventSet();
}
};
constructors[BACKUP_ENTRY_PROCESSOR] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {
@Override
public IdentifiedDataSerializable createNew(Integer arg) {
return new CacheBackupEntryProcessorOperation();
}
};
return new ArrayDataSerializableFactory(constructors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ public void addRemoveTimeNanos(long duration) {
for (;;) {
long nanos = removeTimeTakenNanos;
if (nanos <= Long.MAX_VALUE - duration) {
if (REMOVALS_UPDATER.compareAndSet(this, nanos, nanos + duration)) {
if (REMOVE_TIME_TAKEN_NANOS_UPDATER.compareAndSet(this, nanos, nanos + duration)) {
return;
}
} else {
//counter full. Just reset.
if (REMOVALS_UPDATER.compareAndSet(this, nanos, duration)) {
if (REMOVE_TIME_TAKEN_NANOS_UPDATER.compareAndSet(this, nanos, duration)) {
clear();
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2008-2013, 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.cache.impl.operation;

import com.hazelcast.cache.impl.CacheDataSerializerHook;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.Data;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import com.hazelcast.spi.BackupOperation;

import javax.cache.processor.EntryProcessor;
import java.io.IOException;

/**
* Operation of the Cache Backup Entry Processor.
* <p>{@link com.hazelcast.cache.BackupAwareEntryProcessor} is executed on the partition.
* Executing this method applies a backup entry processor to the requested
* {@link com.hazelcast.cache.impl.ICacheRecordStore} which provides the required
* functionality to apply the backup using the given {@link javax.cache.processor.EntryProcessor}.</p>
*/
public class CacheBackupEntryProcessorOperation
extends AbstractCacheOperation
implements BackupOperation, IdentifiedDataSerializable {

private EntryProcessor entryProcessor;
private Object[] arguments;

public CacheBackupEntryProcessorOperation() {
}

public CacheBackupEntryProcessorOperation(String name, Data key, EntryProcessor entryProcessor,
Object... arguments) {
super(name, key);
this.entryProcessor = entryProcessor;
this.arguments = arguments;
}

@Override
public int getId() {
return CacheDataSerializerHook.BACKUP_ENTRY_PROCESSOR;
}

@Override
public void run()
throws Exception {
cache.invoke(key, entryProcessor, arguments);
}

@Override
protected void writeInternal(ObjectDataOutput out)
throws IOException {
super.writeInternal(out);
out.writeObject(entryProcessor);
out.writeBoolean(arguments != null);
if (arguments != null) {
out.writeInt(arguments.length);
for (Object arg : arguments) {
out.writeObject(arg);
}
}
}

@Override
protected void readInternal(ObjectDataInput in)
throws IOException {
super.readInternal(in);
entryProcessor = in.readObject();
final boolean hasArguments = in.readBoolean();
if (hasArguments) {
final int size = in.readInt();
arguments = new Object[size];
for (int i = 0; i < size; i++) {
arguments[i] = in.readObject();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hazelcast.cache.impl.operation;

import com.hazelcast.cache.BackupAwareEntryProcessor;
import com.hazelcast.cache.impl.CacheDataSerializerHook;
import com.hazelcast.cache.impl.record.CacheRecord;
import com.hazelcast.nio.ObjectDataInput;
Expand All @@ -39,6 +40,7 @@ public class CacheEntryProcessorOperation
private Object[] arguments;

private transient CacheRecord backupRecord;
private transient EntryProcessor backupEntryProcessor;

public CacheEntryProcessorOperation() {
}
Expand All @@ -58,8 +60,11 @@ public boolean shouldBackup() {

@Override
public Operation getBackupOperation() {
// TODO: Add sub-interface to backup using same entry processor instead of put backup
return new CachePutBackupOperation(name, key, backupRecord);
if (backupEntryProcessor != null) {
return new CacheBackupEntryProcessorOperation(name, key, backupEntryProcessor, arguments);
} else {
return new CachePutBackupOperation(name, key, backupRecord);
}
}

@Override
Expand All @@ -71,7 +76,13 @@ public int getId() {
public void run()
throws Exception {
response = cache.invoke(key, entryProcessor, arguments);
backupRecord = cache.getRecord(key);
if (entryProcessor instanceof BackupAwareEntryProcessor) {
BackupAwareEntryProcessor processor = (BackupAwareEntryProcessor) entryProcessor;
backupEntryProcessor = processor.createBackupEntryProcessor();
}
if (backupEntryProcessor == null) {
backupRecord = cache.getRecord(key);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void onMessage(Object msg) {

private void logDroppedMessage(Object msg) {
if (logger.isFinestEnabled()) {
logger.info("Dropped: " + msg);
logger.finest("Dropped: " + msg);
}
}

Expand Down
Loading

0 comments on commit 81a7714

Please sign in to comment.