Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nullable and Notnull annotations to IMap #15003

Merged
merged 2 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.hazelcast.util.CollectionUtil;
import com.hazelcast.util.executor.CompletedFuture;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
Expand Down Expand Up @@ -139,7 +140,7 @@ protected boolean setTtlInternal(Object key, long ttl, TimeUnit timeUnit) {
}

@Override
public ICompletableFuture<V> getAsync(K key) {
public ICompletableFuture<V> getAsync(@Nonnull K key) {
checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);

final Object ncKey = toNearCacheKey(key);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2008-2019, 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.client.map;

import com.hazelcast.client.test.TestHazelcastFactory;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.AbstractMapNullTest;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.annotation.ParallelJVMTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.After;
import org.junit.Before;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

/**
* Member implementation for basic map methods nullability tests
*/
@RunWith(HazelcastParallelClassRunner.class)
@Category({QuickTest.class, ParallelJVMTest.class})
public class ClientMapNullTest extends AbstractMapNullTest {

private final TestHazelcastFactory hazelcastFactory = new TestHazelcastFactory();
private HazelcastInstance member;
private HazelcastInstance client;

@Before
public void setup() {
member = hazelcastFactory.newHazelcastInstance();
client = hazelcastFactory.newHazelcastClient();
}

@After
public void tearDown() {
hazelcastFactory.terminateAll();
}

@Override
protected boolean isNotClient() {
return false;
}

@Override
protected HazelcastInstance getDriver() {
return client;
}
}
1,049 changes: 603 additions & 446 deletions hazelcast/src/main/java/com/hazelcast/core/IMap.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import com.hazelcast.spi.ObjectNamespace;
import com.hazelcast.spi.impl.operationservice.Operation;

import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;

import static com.hazelcast.cp.internal.datastructures.unsafe.lock.LockServiceImpl.SERVICE_NAME;
import static com.hazelcast.util.ExceptionUtil.rethrowAllowInterrupted;
import static com.hazelcast.util.ThreadUtil.getThreadId;
import static com.hazelcast.util.TimeUtil.timeInMsOrTimeIfNullUnit;
import static java.lang.Thread.currentThread;

public final class LockProxySupport {
Expand Down Expand Up @@ -123,14 +125,16 @@ public boolean tryLock(NodeEngine nodeEngine, Data key) {
}
}

public boolean tryLock(NodeEngine nodeEngine, Data key, long timeout, TimeUnit timeunit) throws InterruptedException {
public boolean tryLock(NodeEngine nodeEngine, Data key,
long timeout, @Nullable TimeUnit timeunit) throws InterruptedException {
return tryLock(nodeEngine, key, timeout, timeunit, -1, TimeUnit.MILLISECONDS);
}

public boolean tryLock(NodeEngine nodeEngine, Data key, long timeout, TimeUnit timeunit,
long leaseTime, TimeUnit leaseTimeunit) throws InterruptedException {
long timeoutInMillis = getTimeInMillis(timeout, timeunit);
long leaseTimeInMillis = getTimeInMillis(leaseTime, leaseTimeunit);
public boolean tryLock(NodeEngine nodeEngine, Data key,
long timeout, @Nullable TimeUnit timeunit,
long leaseTime, @Nullable TimeUnit leaseTimeunit) throws InterruptedException {
long timeoutInMillis = timeInMsOrTimeIfNullUnit(timeout, timeunit);
long leaseTimeInMillis = timeInMsOrTimeIfNullUnit(leaseTime, leaseTimeunit);
LockOperation operation = new LockOperation(namespace, key, getThreadId(), leaseTimeInMillis, timeoutInMillis);
InternalCompletableFuture<Boolean> f = invoke(nodeEngine, operation, key);

Expand All @@ -141,10 +145,6 @@ public boolean tryLock(NodeEngine nodeEngine, Data key, long timeout, TimeUnit t
}
}

private long getTimeInMillis(final long time, final TimeUnit timeunit) {
return timeunit != null ? timeunit.toMillis(time) : time;
}

public void unlock(NodeEngine nodeEngine, Data key) {
UnlockOperation operation = new UnlockOperation(namespace, key, getThreadId());
InternalCompletableFuture<Number> f = invoke(nodeEngine, operation, key);
Expand Down
Loading