EMMA Coverage Report (generated Tue Jun 21 05:51:52 EDT 2011)
[all classes][org.jclouds.compute.predicates]

COVERAGE SUMMARY FOR SOURCE FILE [RetryIfSocketNotYetOpen.java]

nameclass, %method, %block, %line, %
RetryIfSocketNotYetOpen.java100% (1/1)20%  (1/5)12%  (13/106)22%  (4.5/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RetryIfSocketNotYetOpen100% (1/1)20%  (1/5)12%  (13/106)22%  (4.5/20)
RetryIfSocketNotYetOpen (SocketOpen, Logger, long): void 0%   (0/1)0%   (0/15)0%   (0/6)
apply (IPSocket): boolean 0%   (0/1)0%   (0/61)0%   (0/7)
seconds (long): RetryIfSocketNotYetOpen 0%   (0/1)0%   (0/5)0%   (0/2)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
RetryIfSocketNotYetOpen (SocketOpen, ComputeServiceConstants$Timeouts): void 100% (1/1)100% (13/13)100% (5/5)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.compute.predicates;
20 
21import java.util.concurrent.TimeUnit;
22 
23import javax.annotation.Resource;
24import javax.inject.Inject;
25import javax.inject.Named;
26 
27import org.jclouds.compute.reference.ComputeServiceConstants;
28import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
29import org.jclouds.logging.Logger;
30import org.jclouds.net.IPSocket;
31import org.jclouds.predicates.RetryablePredicate;
32import org.jclouds.predicates.SocketOpen;
33 
34import com.google.common.base.Predicate;
35 
36/**
37 * 
38 * 
39 * Not singleton as seconds are mutable
40 * 
41 * @author Adrian Cole
42 * 
43 */
44public class RetryIfSocketNotYetOpen implements Predicate<IPSocket> {
45   @Resource
46   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
47   private Logger logger = Logger.NULL;
48 
49   private final SocketOpen socketTester;
50   private long seconds;
51 
52   public RetryIfSocketNotYetOpen seconds(long seconds) {
53      this.seconds = seconds;
54      return this;
55   }
56 
57   @Inject
58   public RetryIfSocketNotYetOpen(SocketOpen socketTester, Timeouts timeouts) {
59      this.socketTester = socketTester;
60      this.seconds = timeouts.portOpen;
61   }
62 
63   public RetryIfSocketNotYetOpen(SocketOpen socketTester, Logger logger, long seconds) {
64      this.socketTester = socketTester;
65      this.logger = logger;
66      this.seconds = seconds;
67   }
68 
69   @Override
70   public String toString() {
71      return "retryIfSocketNotYetOpen(" + seconds + ")";
72   }
73 
74   @Override
75   public boolean apply(IPSocket socket) {
76      logger.debug(">> blocking on socket %s for %d seconds", socket, seconds);
77      RetryablePredicate<IPSocket> tester = new RetryablePredicate<IPSocket>(socketTester, seconds, 1, TimeUnit.SECONDS);
78      boolean passed = tester.apply(socket);
79      if (passed)
80         logger.debug("<< socket %s opened", socket);
81      else
82         logger.warn("<< socket %s didn't open after %d seconds", socket, seconds);
83      return passed;
84   }
85}

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