1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.engine;
\r
21 import java.util.List;
\r
23 import compbio.data.sequence.FastaSequence;
\r
24 import compbio.engine.client.Executable;
\r
25 import compbio.engine.local.LocalExecutorService;
\r
26 import compbio.metadata.Limit;
\r
27 import compbio.metadata.PresetManager;
\r
29 public class LoadBalancer {
\r
31 private LoadBalancer() {
\r
34 public static Executable.ExecProvider getEngine(Executable<?> executable) {
\r
35 if (LocalExecutorService.getExecutor().canAcceptMoreWork()) {
\r
36 return Executable.ExecProvider.Local;
\r
38 return Executable.ExecProvider.Cluster;
\r
41 public static <T, V> Executable.ExecProvider getEngine(
\r
42 Executable<V> executable, List<FastaSequence> dataSet) {
\r
44 // If data set is deemed too big for local execution, than give a
\r
46 // If limit is not defined then defaults to executing on the cluster
\r
47 Limit<V> limit = executable
\r
48 .getLimit(PresetManager.LOCAL_ENGINE_LIMIT_PRESET);
\r
50 if (limit == null || limit.isExceeded(dataSet)) {
\r
51 return Executable.ExecProvider.Cluster;
\r
53 // Even if the data satisfies criteria for local execution it may still
\r
54 // be executed on the cluster as the maximum capacity for local engine
\r
56 return getEngine(executable);
\r