|
| 1 | +/* |
| 2 | + * Copyright 2016 Google Inc. All Rights Reserved. |
| 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.cloud.logging; |
| 18 | + |
| 19 | +import com.google.cloud.GrpcServiceOptions; |
| 20 | +import com.google.cloud.logging.spi.DefaultLoggingRpc; |
| 21 | +import com.google.cloud.logging.spi.LoggingRpc; |
| 22 | +import com.google.cloud.logging.spi.LoggingRpcFactory; |
| 23 | +import com.google.common.collect.ImmutableSet; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | +import java.util.Set; |
| 27 | + |
| 28 | +public class LoggingOptions extends GrpcServiceOptions<Logging, LoggingRpc, LoggingOptions> { |
| 29 | + |
| 30 | + private static final long serialVersionUID = -2996451684945061075L; |
| 31 | + private static final String LOGGING_SCOPE = "https://www.googleapis.com/auth/logging.admin"; |
| 32 | + private static final Set<String> SCOPES = ImmutableSet.of(LOGGING_SCOPE); |
| 33 | + private static final String DEFAULT_HOST = "https://logging.googleapis.com"; |
| 34 | + |
| 35 | + public static class DefaultLoggingFactory implements LoggingFactory { |
| 36 | + private static final LoggingFactory INSTANCE = new DefaultLoggingFactory(); |
| 37 | + |
| 38 | + @Override |
| 39 | + public Logging create(LoggingOptions options) { |
| 40 | + // todo(mziccard) uncomment once LoggingImpl is implemented |
| 41 | + // return new LoggingImpl(options); |
| 42 | + return null; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Returns a default {@code LoggingOptions} instance. |
| 48 | + */ |
| 49 | + public static LoggingOptions defaultInstance() { |
| 50 | + return builder().build(); |
| 51 | + } |
| 52 | + |
| 53 | + public static class DefaultLoggingRpcFactory implements LoggingRpcFactory { |
| 54 | + private static final LoggingRpcFactory INSTANCE = new DefaultLoggingRpcFactory(); |
| 55 | + |
| 56 | + @Override |
| 57 | + public LoggingRpc create(LoggingOptions options) { |
| 58 | + try { |
| 59 | + return new DefaultLoggingRpc(options); |
| 60 | + } catch (IOException e) { |
| 61 | + throw new LoggingException(e, true); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + protected String defaultHost() { |
| 68 | + return DEFAULT_HOST; |
| 69 | + } |
| 70 | + |
| 71 | + public static class Builder extends |
| 72 | + GrpcServiceOptions.Builder<Logging, LoggingRpc, LoggingOptions, Builder> { |
| 73 | + |
| 74 | + private Builder() {} |
| 75 | + |
| 76 | + private Builder(LoggingOptions options) { |
| 77 | + super(options); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public LoggingOptions build() { |
| 82 | + return new LoggingOptions(this); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + protected LoggingOptions(Builder builder) { |
| 87 | + super(LoggingFactory.class, LoggingRpcFactory.class, builder); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + protected ExecutorFactory executorFactory() { |
| 92 | + return super.executorFactory(); |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + protected LoggingFactory defaultServiceFactory() { |
| 97 | + return DefaultLoggingFactory.INSTANCE; |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + protected LoggingRpcFactory defaultRpcFactory() { |
| 102 | + return DefaultLoggingRpcFactory.INSTANCE; |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + protected Set<String> scopes() { |
| 107 | + return SCOPES; |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public boolean equals(Object obj) { |
| 112 | + return obj instanceof LoggingOptions && baseEquals((LoggingOptions) obj); |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public int hashCode() { |
| 117 | + return baseHashCode(); |
| 118 | + } |
| 119 | + |
| 120 | + @SuppressWarnings("unchecked") |
| 121 | + @Override |
| 122 | + public Builder toBuilder() { |
| 123 | + return new Builder(this); |
| 124 | + } |
| 125 | + |
| 126 | + public static Builder builder() { |
| 127 | + return new Builder(); |
| 128 | + } |
| 129 | +} |
0 commit comments