Skip to content

Commit

Permalink
Merge pull request google#919 from google/moe_writing_branch_from_156…
Browse files Browse the repository at this point in the history
…c8cc762fab971efb727c7ab107fa243be2fc9

Merge internal changes
  • Loading branch information
sameb committed Apr 23, 2015
2 parents 25b0a46 + 5be3e95 commit 57e87fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
18 changes: 14 additions & 4 deletions core/src/com/google/inject/internal/CycleDetectingLock.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.google.inject.internal;

import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.Multimaps;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
Expand Down Expand Up @@ -103,7 +107,7 @@ class CycleDetectingLockFactory<ID> {
* Guarded by {@code this}.
*/
private final Multimap<Long, ReentrantCycleDetectingLock> locksOwnedByThread =
MultimapBuilder.linkedHashKeys().linkedHashSetValues().build();
LinkedHashMultimap.create();

/**
* Creates new lock within this factory context. We can guarantee that locks created by
Expand Down Expand Up @@ -234,8 +238,14 @@ private ListMultimap<Long, ID> detectPotentialLocksCycle() {
return ImmutableListMultimap.of();
}

ListMultimap<Long, ID> potentialLocksCycle =
MultimapBuilder.linkedHashKeys().arrayListValues().build();
ListMultimap<Long, ID> potentialLocksCycle = Multimaps.newListMultimap(
new LinkedHashMap<Long, Collection<ID>>(),
new Supplier<List<ID>>() {
@Override
public List<ID> get() {
return Lists.newArrayList();
}
});
// lock that is a part of a potential locks cycle, starts with current lock
ReentrantCycleDetectingLock lockOwnerWaitingOn = this;
// try to find a dependency path between lock's owner thread and a current thread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.inject.service;

import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Runnables;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
Expand All @@ -31,6 +30,10 @@
* @author [email protected] (Dhanji R. Prasanna)
*/
public abstract class AsyncService implements Service {
private static final Runnable DO_NOTHING = new Runnable() {
@Override public void run() {}
};

private final ExecutorService executor;

private volatile State state;
Expand All @@ -45,7 +48,7 @@ public synchronized final Future<State> start() {

// Starts are idempotent.
if (state == State.STARTED) {
return new FutureTask<State>(Runnables.doNothing(), State.STARTED);
return new FutureTask<State>(DO_NOTHING, State.STARTED);
}

return executor.submit(new Callable<State>() {
Expand All @@ -70,7 +73,7 @@ public synchronized final Future<State> stop() {

// Likewise, stops are idempotent.
if (state == State.STOPPED) {
return new FutureTask<State>(Runnables.doNothing(), State.STOPPED);
return new FutureTask<State>(DO_NOTHING, State.STOPPED);
}

return executor.submit(new Callable<State>() {
Expand Down
13 changes: 1 addition & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ See the Apache License Version 2.0 for the specific language governing permissio
</modules>
<!-- Disable doclint under JDK 8 -->
<reporting>
<plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand All @@ -466,16 +466,5 @@ See the Apache License Version 2.0 for the specific language governing permissio
</build>
</profile>
</profiles>

<!-- TODO(cgruber): Update the google parent pom or migrate to sonatype's -->
<!-- TODO(cgruber): Comment out dagger-adapter from extensions/pom.xml if v2 is not released. -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</project>

0 comments on commit 57e87fe

Please sign in to comment.