fixed crashing when removing mods

This commit is contained in:
huangyuhui
2015-12-29 20:35:40 +08:00
parent e3f0254736
commit 3471b4fec7
20 changed files with 152 additions and 243 deletions

View File

@@ -1,12 +1,12 @@
/**
* Copyright 2013 Netflix, Inc.
*
*
* 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.
@@ -23,7 +23,8 @@ import rx.subscriptions.Subscriptions;
import rx.util.functions.Action0;
import rx.util.functions.Func0;
/* package */abstract class AbstractScheduler implements Scheduler {
/* package */
abstract class AbstractScheduler implements Scheduler {
@Override
public Subscription schedule(Action0 action) {
@@ -41,12 +42,9 @@ import rx.util.functions.Func0;
}
private static Func0<Subscription> asFunc0(final Action0 action) {
return new Func0<Subscription>() {
@Override
public Subscription call() {
action.call();
return Subscriptions.empty();
}
return () -> {
action.call();
return Subscriptions.empty();
};
}

View File

@@ -1,12 +1,12 @@
/**
* Copyright 2013 Netflix, Inc.
*
*
* 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.
@@ -27,26 +27,30 @@ import rx.Subscription;
import rx.util.functions.Func0;
/**
* A {@link Scheduler} implementation that uses an {@link Executor} or {@link ScheduledExecutorService} implementation.
* A {@link Scheduler} implementation that uses an {@link Executor} or
* {@link ScheduledExecutorService} implementation.
* <p>
* Note that if an {@link Executor} implementation is used instead of {@link ScheduledExecutorService} then a system-wide Timer will be used to handle delayed events.
* Note that if an {@link Executor} implementation is used instead of
* {@link ScheduledExecutorService} then a system-wide Timer will be used to
* handle delayed events.
*/
public class ExecutorScheduler extends AbstractScheduler {
private final Executor executor;
/**
* Setup a ScheduledExecutorService that we can use if someone provides an Executor instead of ScheduledExecutorService.
* Setup a ScheduledExecutorService that we can use if someone provides an
* Executor instead of ScheduledExecutorService.
*/
private final static ScheduledExecutorService SYSTEM_SCHEDULED_EXECUTOR;
static {
int count = Runtime.getRuntime().availableProcessors();
if (count > 8) {
if (count > 8)
count = count / 2;
}
// we don't need more than 8 to handle just scheduling and doing no work
if (count > 8) {
if (count > 8)
count = 8;
}
SYSTEM_SCHEDULED_EXECUTOR = Executors.newScheduledThreadPool(count, new ThreadFactory() {
final AtomicInteger counter = new AtomicInteger();
@@ -74,37 +78,18 @@ public class ExecutorScheduler extends AbstractScheduler {
public Subscription schedule(Func0<Subscription> action, long dueTime, TimeUnit unit) {
final DiscardableAction discardableAction = new DiscardableAction(action);
if (executor instanceof ScheduledExecutorService) {
((ScheduledExecutorService) executor).schedule(new Runnable() {
@Override
public void run() {
discardableAction.call();
}
if (executor instanceof ScheduledExecutorService)
((ScheduledExecutorService) executor).schedule(discardableAction::call, dueTime, unit);
else if (dueTime == 0)
// no delay so put on the thread-pool right now
return (schedule(action));
else
// there is a delay and this isn't a ScheduledExecutorService so we'll use a system-wide ScheduledExecutorService
// to handle the scheduling and once it's ready then execute on this Executor
SYSTEM_SCHEDULED_EXECUTOR.schedule(() -> {
// now execute on the real Executor
executor.execute(discardableAction::call);
}, dueTime, unit);
} else {
if (dueTime == 0) {
// no delay so put on the thread-pool right now
return (schedule(action));
} else {
// there is a delay and this isn't a ScheduledExecutorService so we'll use a system-wide ScheduledExecutorService
// to handle the scheduling and once it's ready then execute on this Executor
SYSTEM_SCHEDULED_EXECUTOR.schedule(new Runnable() {
@Override
public void run() {
// now execute on the real Executor
executor.execute(new Runnable() {
@Override
public void run() {
discardableAction.call();
}
});
}
}, dueTime, unit);
}
}
return discardableAction;
}
@@ -112,12 +97,7 @@ public class ExecutorScheduler extends AbstractScheduler {
public Subscription schedule(Func0<Subscription> action) {
final DiscardableAction discardableAction = new DiscardableAction(action);
executor.execute(new Runnable() {
@Override
public void run() {
discardableAction.call();
}
});
executor.execute(discardableAction::call);
return discardableAction;

View File

@@ -1,19 +0,0 @@
/**
* Copyright 2013 Netflix, Inc.
*
* 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.
*/
/**
* Rx Schedulers
*/
package rx.concurrency;