Skip to content

Commit

Permalink
Merge pull request #85 from fengjiachun/feat/v1.3
Browse files Browse the repository at this point in the history
v1.3
  • Loading branch information
fengjiachun authored Apr 13, 2019
2 parents 0becbce + b468b61 commit ef497cd
Show file tree
Hide file tree
Showing 125 changed files with 1,033 additions and 1,522 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
language: java
sudo: false

jdk:
- oraclejdk8
- openjdk7
- openjdk8
- openjdk11

cache:
directories:
- $HOME/.m2

install:
- mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V

after_success:
- travis_retry mvn clean test
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ public class HelloJupiterClient {

[Server/Client代码示例](https://github.com/fengjiachun/Jupiter/tree/master/jupiter-example/src/main/java/org/jupiter/example/round)

###### 新特性

v1.3 新增 `InvokeType.AUTO`, 当你的接口返回值是一个 `CompletableFuture` 或者它的子类将自动适配为异步调用, 否则为同步调用
[具体 demo 请参考这里](/jupiter-example/src/main/java/org/jupiter/example/round/AutoJupiterClient.java)

##### 结合Spring使用示例:
###### 1. [Server端配置](/jupiter-example/src/main/resources/spring-provider.xml):

Expand Down
6 changes: 5 additions & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Jupiter release notes
------------------------

###
### 2019-04-13: version 1.3.0
- 不再支持 java7,仅支持 java8 及以上版本
- 移除 AbstractFuture,直接使用 java8 的CompletableFuture
- AbstractRegistryService 中的 ReadWriteLock 替换为 StampedLock 以支持乐观锁
- InvokeType.AUTO, 当你的接口返回值是一个 CompletableFuture, 自动转成异步调用, 否则为同步调用

### 2018-09-11: version 1.2.26
- Bug fix: [Object[] 包含 null 时序列化/反序列化错误] (https://github.com/fengjiachun/Jupiter/issues/73#issuecomment-420119074)
Expand Down
2 changes: 1 addition & 1 deletion jupiter-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>org.jupiter-rpc</groupId>
<artifactId>jupiter</artifactId>
<version>1.2.26</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion jupiter-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>jupiter</artifactId>
<groupId>org.jupiter-rpc</groupId>
<version>1.2.26</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -56,9 +55,7 @@ public void dumpJvmInfoIfNeeded() {
if (dumpNeeded.getAndSet(false)) {
String now = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
String name = threadPoolName + "_" + now;
FileOutputStream fileOutput = null;
try {
fileOutput = new FileOutputStream(new File(dumpPrefixName + "_dump_" + name + ".log"));
try (FileOutputStream fileOutput = new FileOutputStream(new File(dumpPrefixName + "_dump_" + name + ".log"))) {

List<String> stacks = JvmTools.jStack();
for (String s : stacks) {
Expand All @@ -75,12 +72,6 @@ public void dumpJvmInfoIfNeeded() {
}
} catch (Throwable t) {
logger.error("Dump jvm info error: {}.", stackTrace(t));
} finally {
if (fileOutput != null) {
try {
fileOutput.close();
} catch (IOException ignored) {}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,18 @@ public Thread newThread(Runnable r) {

final Runnable r2 = wrapRunnable(r);

Runnable r3 = new Runnable() {

@Override
public void run() {
AffinityLock al = null;
try {
al = acquireLockBasedOnLast();
} catch (Throwable ignored) { /* defensive: ignored error on acquiring lock */ }
try {
r2.run();
} finally {
if (al != null) {
try {
al.release();
} catch (Throwable ignored) { /* defensive: ignored error on releasing lock */ }
}
Runnable r3 = () -> {
AffinityLock al = null;
try {
al = acquireLockBasedOnLast();
} catch (Throwable ignored) { /* defensive: ignored error on acquiring lock */ }
try {
r2.run();
} finally {
if (al != null) {
try {
al.release();
} catch (Throwable ignored) { /* defensive: ignored error on releasing lock */ }
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ private static Object val(Object[] kvs, int idx) {
return kvs[(idx << 1) + 3];
}

@SuppressWarnings("SameParameterValue")
private static boolean CAS_key(Object[] kvs, int idx, Object old, Object key) {
return unsafe.compareAndSwapObject(kvs, rawIndex(kvs, (idx << 1) + 2), old, key);
}
Expand Down Expand Up @@ -1607,8 +1608,8 @@ public boolean hasNext() {
* requires the creation of {@link java.util.Map.Entry} objects with each
* iteration. The {@link NonBlockingHashMap} does not normally create or
* using {@link java.util.Map.Entry} objects so they will be created soley
* to support this iteration. Iterating using {@link #keySet} or {@link
* #values} will be more efficient.
* to support this iteration. Iterating using keySet or values will be
* more efficient.
*/
@Override
public Set<Map.Entry<TypeK, TypeV>> entrySet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ boolean CAS_newchm(CHM newchm) {

// --- key,val -------------------------------------------------------------
// Access K,V for a given idx
@SuppressWarnings("SameParameterValue")
private boolean CAS_key(int idx, long old, long key) {
return unsafe.compareAndSwapLong(_keys, rawIndex(_keys, idx), old, key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@
*/
public class TaskDispatcher implements Dispatcher<Runnable>, Executor {

private static final EventFactory<MessageEvent<Runnable>> eventFactory = new EventFactory<MessageEvent<Runnable>>() {

@Override
public MessageEvent<Runnable> newInstance() {
return new MessageEvent<>();
}
};
private static final EventFactory<MessageEvent<Runnable>> eventFactory = MessageEvent::new;

private final Disruptor<MessageEvent<Runnable>> disruptor;
private final ExecutorService reserveExecutor;
Expand Down Expand Up @@ -129,7 +123,7 @@ public TaskDispatcher(int numWorkers,
numReserveWorkers,
60L,
TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new SynchronousQueue<>(),
new NamedThreadFactory(name),
handler);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ final LinkedQueueNode<E> lvProducerNode() {
return (LinkedQueueNode<E>) unsafe.getObjectVolatile(this, P_NODE_OFFSET);
}

@SuppressWarnings("unchecked")
final boolean casProducerNode(LinkedQueueNode<E> expect, LinkedQueueNode<E> newValue) {
return unsafe.compareAndSwapObject(this, P_NODE_OFFSET, expect, newValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void fill(Supplier<E> s, WaitStrategy wait, ExitCondition exit) {
}

// $gen:ignore
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "CastCanBeRemovedNarrowingVariableType"})
protected LinkedQueueNode<E> xchgProducerNode(LinkedQueueNode<E> nextNode) {
Object oldNode;
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -73,19 +71,15 @@ public List<S> sort() {
return sortList;
}

Collections.sort(sortList, new Comparator<S>() {
sortList.sort((o1, o2) -> {
SpiMetadata o1_spi = o1.getClass().getAnnotation(SpiMetadata.class);
SpiMetadata o2_spi = o2.getClass().getAnnotation(SpiMetadata.class);

@Override
public int compare(S o1, S o2) {
SpiMetadata o1_spi = o1.getClass().getAnnotation(SpiMetadata.class);
SpiMetadata o2_spi = o2.getClass().getAnnotation(SpiMetadata.class);

int o1_priority = o1_spi == null ? 0 : o1_spi.priority();
int o2_priority = o2_spi == null ? 0 : o2_spi.priority();
int o1_priority = o1_spi == null ? 0 : o1_spi.priority();
int o2_priority = o2_spi == null ? 0 : o2_spi.priority();

// 优先级高的排前边
return o2_priority - o1_priority;
}
// 优先级高的排前边
return o2_priority - o1_priority;
});

return sortList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class MD5Util {
private static final ThreadLocal<MessageDigest> messageDigestHolder = new ThreadLocal<>();

// 用来将字节转换成 16 进制表示的字符
@SuppressWarnings("CStyleArrayDeclaration")
private static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static String[] split(String str, char separator, boolean preserveAllToke
if (match || preserveAllTokens) {
list.add(str.substring(start, i));
}
return list.toArray(new String[list.size()]);
return list.toArray(new String[0]);
}

private static final String[] EMPTY_STRING_ARRAY = new String[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import org.jupiter.common.util.internal.UnsafeUtil;
Expand Down Expand Up @@ -83,23 +82,15 @@ private SystemClock(long precision) {
}

private void scheduleClockUpdating() {
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {

@Override
public Thread newThread(Runnable runnable) {
Thread t = new Thread(runnable, "system.clock");
t.setDaemon(true);
return t;
}
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(runnable -> {
Thread t = new Thread(runnable, "system.clock");
t.setDaemon(true);
return t;
});

scheduler.scheduleAtFixedRate(new Runnable() {

@Override
public void run() {
// Update the timestamp with ordered semantics.
UnsafeUtil.getUnsafe().putOrderedLong(SystemClock.this, NOW_VALUE_OFFSET, System.currentTimeMillis());
}
scheduler.scheduleAtFixedRate(() -> {
// Update the timestamp with ordered semantics.
UnsafeUtil.getUnsafe().putOrderedLong(SystemClock.this, NOW_VALUE_OFFSET, System.currentTimeMillis());
}, precision, precision, TimeUnit.MILLISECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,7 @@ public static String get(final String key, String def) {
if (System.getSecurityManager() == null) {
value = System.getProperty(key);
} else {
value = AccessController.doPrivileged(new PrivilegedAction<String>() {

@Override
public String run() {
return System.getProperty(key);
}
});
value = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(key));
}
} catch (Exception e) {
if (logger.isWarnEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void throwException(Throwable t) {
if (unsafe != null) {
unsafe.throwException(t);
} else {
ThrowUtil.<RuntimeException>throwException0(t);
ThrowUtil.throwException0(t);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ public class ByteObjectHashMap<V> implements ByteObjectMap<V> {

private final Set<Byte> keySet = new KeySet();
private final Set<Entry<Byte, V>> entrySet = new EntrySet();
private final Iterable<PrimitiveEntry<V>> entries = new Iterable<PrimitiveEntry<V>>() {

@Override
public Iterator<PrimitiveEntry<V>> iterator() {
return new PrimitiveIterator();
}
};
private final Iterable<PrimitiveEntry<V>> entries = PrimitiveIterator::new;

public ByteObjectHashMap() {
this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V> {

private final Set<Integer> keySet = new KeySet();
private final Set<Entry<Integer, V>> entrySet = new EntrySet();
private final Iterable<PrimitiveEntry<V>> entries = new Iterable<PrimitiveEntry<V>>() {
@Override
public Iterator<PrimitiveEntry<V>> iterator() {
return new PrimitiveIterator();
}
};
private final Iterable<PrimitiveEntry<V>> entries = PrimitiveIterator::new;

public IntObjectHashMap() {
this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ public class LongObjectHashMap<V> implements LongObjectMap<V> {

private final Set<Long> keySet = new KeySet();
private final Set<Entry<Long, V>> entrySet = new EntrySet();
private final Iterable<PrimitiveEntry<V>> entries = new Iterable<PrimitiveEntry<V>>() {
@Override
public Iterator<PrimitiveEntry<V>> iterator() {
return new PrimitiveIterator();
}
};
private final Iterable<PrimitiveEntry<V>> entries = PrimitiveIterator::new;

public LongObjectHashMap() {
this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap
Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex);
Set<InternalThreadLocal<?>> variablesToRemove;
if (v == InternalThreadLocalMap.UNSET || v == null) {
variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<InternalThreadLocal<?>, Boolean>());
variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<>());
threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove);
} else {
variablesToRemove = (Set<InternalThreadLocal<?>>) v;
Expand Down Expand Up @@ -150,7 +150,6 @@ public final void set(V value) {
/**
* Sets the value to uninitialized; a proceeding call to get() will trigger a call to initialValue().
*/
@SuppressWarnings("unchecked")
public final void remove() {
remove(InternalThreadLocalMap.getIfSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,7 @@ public static ClassLoader getSystemClassLoader() {
if (System.getSecurityManager() == null) {
return ClassLoader.getSystemClassLoader();
} else {
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

@Override
public ClassLoader run() {
return ClassLoader.getSystemClassLoader();
}
});
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) ClassLoader::getSystemClassLoader);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ public void error(String msg, Throwable t) {
* <p/>
* See bug report #13 for more details.
*/
@SuppressWarnings("SameParameterValue")
private void log(String callerFQCN, Level level, String msg, Throwable t) {
// millis and thread are filled by the constructor
LogRecord record = new LogRecord(level, msg);
Expand Down
Loading

0 comments on commit ef497cd

Please sign in to comment.