EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.compute.callables]

COVERAGE SUMMARY FOR SOURCE FILE [InitScriptConfigurationForTasks.java]

nameclass, %method, %block, %line, %
InitScriptConfigurationForTasks.java0%   (0/3)0%   (0/14)0%   (0/105)0%   (0/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InitScriptConfigurationForTasks0%   (0/1)0%   (0/8)0%   (0/64)0%   (0/16)
InitScriptConfigurationForTasks (): void 0%   (0/1)0%   (0/20)0%   (0/5)
appendCurrentTimeMillisToAnonymousTaskNames (): InitScriptConfigurationForTasks 0%   (0/1)0%   (0/8)0%   (0/2)
appendIncrementingNumberToAnonymousTaskNames (): InitScriptConfigurationForTasks 0%   (0/1)0%   (0/8)0%   (0/2)
create (): InitScriptConfigurationForTasks 0%   (0/1)0%   (0/4)0%   (0/1)
getAnonymousTaskSuffixSupplier (): Supplier 0%   (0/1)0%   (0/3)0%   (0/1)
getBasedir (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getInitScriptPattern (): String 0%   (0/1)0%   (0/3)0%   (0/1)
initScriptPattern (String): InitScriptConfigurationForTasks 0%   (0/1)0%   (0/15)0%   (0/3)
     
class InitScriptConfigurationForTasks$10%   (0/1)0%   (0/3)0%   (0/17)0%   (0/3)
InitScriptConfigurationForTasks$1 (InitScriptConfigurationForTasks): void 0%   (0/1)0%   (0/6)0%   (0/1)
get (): String 0%   (0/1)0%   (0/9)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)
     
class InitScriptConfigurationForTasks$20%   (0/1)0%   (0/3)0%   (0/24)0%   (0/4)
InitScriptConfigurationForTasks$2 (InitScriptConfigurationForTasks): void 0%   (0/1)0%   (0/11)0%   (0/2)
get (): String 0%   (0/1)0%   (0/11)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.compute.callables;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.io.File;
24import java.util.concurrent.atomic.AtomicInteger;
25 
26import javax.inject.Named;
27import javax.inject.Singleton;
28 
29import org.jclouds.scriptbuilder.InitBuilder;
30 
31import com.google.common.base.Supplier;
32import com.google.inject.Inject;
33 
34/**
35 * 
36 * @author Adrian Cole
37 */
38@Singleton
39public class InitScriptConfigurationForTasks {
40   public static final String PROPERTY_INIT_SCRIPT_PATTERN = "jclouds.compute.init-script-pattern";
41 
42   public static InitScriptConfigurationForTasks create() {
43      return new InitScriptConfigurationForTasks();
44   }
45 
46   private String basedir = "/tmp";
47   private String initScriptPattern = basedir + "/init-%s";
48   private Supplier<String> suffixSupplier;
49 
50   protected InitScriptConfigurationForTasks() {
51      appendCurrentTimeMillisToAnonymousTaskNames();
52   }
53 
54   @Inject(optional = true)
55   public InitScriptConfigurationForTasks initScriptPattern(
56            @Named(PROPERTY_INIT_SCRIPT_PATTERN) String initScriptPattern) {
57      this.initScriptPattern = checkNotNull(initScriptPattern, "initScriptPattern ex. /tmp/init-%s");
58      this.basedir = new File(initScriptPattern).getParent();
59      return this;
60   }
61 
62   public InitScriptConfigurationForTasks appendCurrentTimeMillisToAnonymousTaskNames() {
63      this.suffixSupplier = new Supplier<String>() {
64 
65         @Override
66         public String get() {
67            return System.currentTimeMillis() + "";
68         }
69 
70         @Override
71         public String toString() {
72            return "currentTimeMillis()";
73         }
74      };
75      return this;
76   }
77 
78   public InitScriptConfigurationForTasks appendIncrementingNumberToAnonymousTaskNames() {
79      this.suffixSupplier = new Supplier<String>() {
80         private final AtomicInteger integer = new AtomicInteger();
81 
82         @Override
83         public String get() {
84            return integer.getAndIncrement() + "";
85         }
86 
87         @Override
88         public String toString() {
89            return "incrementingNumber()";
90         }
91      };
92      return this;
93   }
94 
95   /**
96    * Directory where the init script is stored. the runtime directory of the process will be in
97    * this dir/taskName
98    */
99   public String getBasedir() {
100      return basedir;
101   }
102 
103   /**
104    * 
105    * @return the naming convention of init scripts. ex. {@code /tmp/init-%s}, noting logs are under
106    *         the basedir/%s where %s is the taskName
107    * @see InitBuilder#getHomeDir
108    * @see InitBuilder#getLogDir
109    */
110   public String getInitScriptPattern() {
111      return initScriptPattern;
112   }
113 
114   /**
115    * @return suffix where the taskName isn't set. by default this is
116    *         {@link System#currentTimeMillis}
117    * @see #appendCurrentTimeMillisToAnonymousTaskNames
118    * @see #appendIncrementingNumberToAnonymousTaskNames
119    */
120   public Supplier<String> getAnonymousTaskSuffixSupplier() {
121      return suffixSupplier;
122   }
123}

[all classes][org.jclouds.compute.callables]
EMMA 2.0.5312 (C) Vladimir Roubtsov