| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright 2011 Google Inc. |
| 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 * See the License for the specific language governing permissions and |
| 14 * limitations under the License. |
| 15 */ |
| 16 |
| 17 package com.google.ipc.invalidation.ticl; |
| 18 |
| 19 import com.google.ipc.invalidation.external.client.SystemResources; |
| 20 |
| 21 |
| 22 /** |
| 23 * A simple implementation of {@code SystemResources} that just takes the resour
ce components |
| 24 * and constructs a SystemResources object. |
| 25 * |
| 26 */ |
| 27 public class BasicSystemResources implements SystemResources { |
| 28 |
| 29 // Components comprising the system resources. We delegate calls to these as a
ppropriate. |
| 30 private final Scheduler internalScheduler; |
| 31 private final Scheduler listenerScheduler; |
| 32 private final Logger logger; |
| 33 private final NetworkChannel network; |
| 34 private final Storage storage; |
| 35 |
| 36 /** The state of the resources. */ |
| 37 private RunState runState = new RunState(); |
| 38 |
| 39 /** Information about the client operating system/platform, e.g., Windows, Chr
omeOS. */ |
| 40 private final String platform; |
| 41 |
| 42 /** |
| 43 * Constructs an instance from resource components. |
| 44 * |
| 45 * @param logger implementation of the logger |
| 46 * @param internalScheduler scheduler for scheduling the library's internal ev
ents |
| 47 * @param listenerScheduler scheduler for scheduling the listener's events |
| 48 * @param network implementation of the network |
| 49 * @param storage implementation of storage |
| 50 * @param platform if not {@code null}, platform string for client version. If
{@code null}, |
| 51 * a default string will be constructed. |
| 52 */ |
| 53 public BasicSystemResources(Logger logger, Scheduler internalScheduler, |
| 54 Scheduler listenerScheduler, NetworkChannel network, Storage storage, |
| 55 String platform) { |
| 56 this.logger = logger; |
| 57 this.storage = storage; |
| 58 this.network = network; |
| 59 if (platform != null) { |
| 60 this.platform = platform; |
| 61 } else { |
| 62 // If a platform string was not provided, try to compute a reasonable defa
ult. |
| 63 this.platform = System.getProperty("os.name") + "/" + System.getProperty("
os.version") + |
| 64 "/" + System.getProperty("os.arch"); |
| 65 } |
| 66 |
| 67 this.internalScheduler = internalScheduler; |
| 68 this.listenerScheduler = listenerScheduler; |
| 69 |
| 70 // Pass a reference to this object to all of the components, so that they ca
n access |
| 71 // resources. E.g., so that the network can do logging. |
| 72 logger.setSystemResources(this); |
| 73 storage.setSystemResources(this); |
| 74 network.setSystemResources(this); |
| 75 internalScheduler.setSystemResources(this); |
| 76 listenerScheduler.setSystemResources(this); |
| 77 } |
| 78 |
| 79 @Override |
| 80 public void start() { |
| 81 runState.start(); |
| 82 logger.info("Resources started"); |
| 83 } |
| 84 |
| 85 @Override |
| 86 public void stop() { |
| 87 runState.stop(); |
| 88 logger.info("Resources stopped"); |
| 89 } |
| 90 |
| 91 @Override |
| 92 public boolean isStarted() { |
| 93 return runState.isStarted(); |
| 94 } |
| 95 |
| 96 @Override |
| 97 public Logger getLogger() { |
| 98 return logger; |
| 99 } |
| 100 |
| 101 @Override |
| 102 public Storage getStorage() { |
| 103 return storage; |
| 104 } |
| 105 |
| 106 @Override |
| 107 public NetworkChannel getNetwork() { |
| 108 return network; |
| 109 } |
| 110 |
| 111 @Override |
| 112 public Scheduler getInternalScheduler() { |
| 113 return internalScheduler; |
| 114 } |
| 115 |
| 116 @Override |
| 117 public Scheduler getListenerScheduler() { |
| 118 return listenerScheduler; |
| 119 } |
| 120 |
| 121 @Override |
| 122 public String getPlatform() { |
| 123 return platform; |
| 124 } |
| 125 } |
| OLD | NEW |