Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 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 org.onosproject.grpc.ctl; |
| 18 | |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableMap; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableSet; |
Carmelo Cascone | 158b8c4 | 2018-07-04 19:42:37 +0200 | [diff] [blame] | 21 | import com.google.common.util.concurrent.Striped; |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 22 | import io.grpc.CallOptions; |
| 23 | import io.grpc.Channel; |
| 24 | import io.grpc.ClientCall; |
| 25 | import io.grpc.ClientInterceptor; |
| 26 | import io.grpc.ForwardingClientCall; |
| 27 | import io.grpc.ForwardingClientCallListener; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 28 | import io.grpc.ManagedChannel; |
| 29 | import io.grpc.ManagedChannelBuilder; |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 30 | import io.grpc.Metadata; |
| 31 | import io.grpc.MethodDescriptor; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 32 | import io.grpc.Status; |
| 33 | import io.grpc.StatusRuntimeException; |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 34 | import org.onlab.util.Tools; |
| 35 | import org.onosproject.cfg.ComponentConfigService; |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 36 | import org.onosproject.grpc.api.GrpcChannelController; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 37 | import org.onosproject.grpc.api.GrpcChannelId; |
Carmelo Cascone | 6a1ae71 | 2018-08-10 12:19:47 -0700 | [diff] [blame] | 38 | import org.onosproject.grpc.proto.dummy.Dummy; |
| 39 | import org.onosproject.grpc.proto.dummy.DummyServiceGrpc; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 40 | import org.onosproject.net.DeviceId; |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 41 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 42 | import org.osgi.service.component.annotations.Activate; |
| 43 | import org.osgi.service.component.annotations.Component; |
| 44 | import org.osgi.service.component.annotations.Deactivate; |
| 45 | import org.osgi.service.component.annotations.Modified; |
| 46 | import org.osgi.service.component.annotations.Reference; |
| 47 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 48 | import org.slf4j.Logger; |
| 49 | import org.slf4j.LoggerFactory; |
| 50 | |
| 51 | import java.util.Collection; |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 52 | import java.util.Dictionary; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 53 | import java.util.HashSet; |
| 54 | import java.util.Map; |
| 55 | import java.util.Optional; |
| 56 | import java.util.Set; |
| 57 | import java.util.concurrent.ConcurrentHashMap; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 58 | import java.util.concurrent.TimeUnit; |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 59 | import java.util.concurrent.locks.Lock; |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 60 | |
| 61 | import static com.google.common.base.Preconditions.checkNotNull; |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 62 | import static java.lang.String.format; |
Thomas Vachuska | 00b5d4f | 2018-10-30 15:13:20 -0700 | [diff] [blame] | 63 | import static org.onosproject.grpc.ctl.OsgiPropertyConstants.ENABLE_MESSAGE_LOG; |
| 64 | import static org.onosproject.grpc.ctl.OsgiPropertyConstants.ENABLE_MESSAGE_LOG_DEFAULT; |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 65 | |
| 66 | /** |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 67 | * Default implementation of the GrpcChannelController. |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 68 | */ |
Ray Milkey | 5739b2c | 2018-11-06 14:04:51 -0800 | [diff] [blame] | 69 | @Component(immediate = true, service = GrpcChannelController.class, |
Thomas Vachuska | 00b5d4f | 2018-10-30 15:13:20 -0700 | [diff] [blame] | 70 | property = { |
| 71 | ENABLE_MESSAGE_LOG + ":Boolean=" + ENABLE_MESSAGE_LOG_DEFAULT, |
| 72 | }) |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 73 | public class GrpcChannelControllerImpl implements GrpcChannelController { |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 74 | |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 75 | // FIXME: Should use message size to determine whether it needs to log the message or not. |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 76 | private static final String SET_FORWARDING_PIPELINE_CONFIG_METHOD = "p4.P4Runtime/SetForwardingPipelineConfig"; |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 77 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 78 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 79 | protected ComponentConfigService componentConfigService; |
| 80 | |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 81 | /** Indicates whether to log gRPC messages. */ |
| 82 | private static boolean enableMessageLog = ENABLE_MESSAGE_LOG_DEFAULT; |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 83 | |
Carmelo Cascone | 47a853b | 2018-01-05 02:40:58 +0100 | [diff] [blame] | 84 | private final Logger log = LoggerFactory.getLogger(getClass()); |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 85 | |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 86 | private Map<GrpcChannelId, ManagedChannel> channels; |
Carmelo Cascone | 158b8c4 | 2018-07-04 19:42:37 +0200 | [diff] [blame] | 87 | private final Striped<Lock> channelLocks = Striped.lock(30); |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 88 | |
| 89 | @Activate |
| 90 | public void activate() { |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 91 | componentConfigService.registerProperties(getClass()); |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 92 | channels = new ConcurrentHashMap<>(); |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 93 | log.info("Started"); |
| 94 | } |
| 95 | |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 96 | @Modified |
| 97 | public void modified(ComponentContext context) { |
| 98 | if (context != null) { |
| 99 | Dictionary<?, ?> properties = context.getProperties(); |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 100 | enableMessageLog = Tools.isPropertyEnabled( |
| 101 | properties, ENABLE_MESSAGE_LOG, ENABLE_MESSAGE_LOG_DEFAULT); |
| 102 | log.info("Configured. Log of gRPC messages is {} for new channels", |
| 103 | enableMessageLog ? "enabled" : "disabled"); |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 107 | @Deactivate |
| 108 | public void deactivate() { |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 109 | componentConfigService.unregisterProperties(getClass(), false); |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 110 | channels.values().forEach(ManagedChannel::shutdownNow); |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 111 | channels.clear(); |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 112 | log.info("Stopped"); |
| 113 | } |
| 114 | |
| 115 | @Override |
Carmelo Cascone | 47a853b | 2018-01-05 02:40:58 +0100 | [diff] [blame] | 116 | public ManagedChannel connectChannel(GrpcChannelId channelId, |
Carmelo Cascone | a71b849 | 2018-12-17 17:47:50 -0800 | [diff] [blame^] | 117 | ManagedChannelBuilder<?> channelBuilder) { |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 118 | checkNotNull(channelId); |
| 119 | checkNotNull(channelBuilder); |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 120 | |
Carmelo Cascone | 158b8c4 | 2018-07-04 19:42:37 +0200 | [diff] [blame] | 121 | Lock lock = channelLocks.get(channelId); |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 122 | lock.lock(); |
| 123 | |
| 124 | try { |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 125 | if (channels.containsKey(channelId)) { |
| 126 | throw new IllegalArgumentException(format( |
| 127 | "A channel with ID '%s' already exists", channelId)); |
| 128 | } |
| 129 | if (enableMessageLog) { |
| 130 | channelBuilder.intercept(new InternalLogChannelInterceptor(channelId)); |
| 131 | } |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 132 | ManagedChannel channel = channelBuilder.build(); |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 133 | // Forced connection API is still experimental. Use workaround... |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 134 | // channel.getState(true); |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 135 | try { |
| 136 | doDummyMessage(channel); |
| 137 | } catch (StatusRuntimeException e) { |
Carmelo Cascone | a71b849 | 2018-12-17 17:47:50 -0800 | [diff] [blame^] | 138 | shutdownNowAndWait(channel, channelId); |
| 139 | throw e; |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 140 | } |
| 141 | // If here, channel is open. |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 142 | channels.put(channelId, channel); |
| 143 | return channel; |
| 144 | } finally { |
| 145 | lock.unlock(); |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 146 | } |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 147 | } |
| 148 | |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 149 | private boolean doDummyMessage(ManagedChannel channel) throws StatusRuntimeException { |
Carmelo Cascone | 47a853b | 2018-01-05 02:40:58 +0100 | [diff] [blame] | 150 | DummyServiceGrpc.DummyServiceBlockingStub dummyStub = DummyServiceGrpc |
| 151 | .newBlockingStub(channel) |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 152 | .withDeadlineAfter(CONNECTION_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
| 153 | try { |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 154 | return dummyStub.sayHello(Dummy.DummyMessageThatNoOneWouldReallyUse |
| 155 | .getDefaultInstance()) != null; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 156 | } catch (StatusRuntimeException e) { |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 157 | if (e.getStatus().equals(Status.UNIMPLEMENTED)) { |
Carmelo Cascone | 47a853b | 2018-01-05 02:40:58 +0100 | [diff] [blame] | 158 | // UNIMPLEMENTED means that the server received our message but |
| 159 | // doesn't know how to handle it. Hence, channel is open. |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 160 | return true; |
| 161 | } else { |
| 162 | throw e; |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public boolean isChannelOpen(GrpcChannelId channelId) { |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 169 | checkNotNull(channelId); |
| 170 | |
Carmelo Cascone | 158b8c4 | 2018-07-04 19:42:37 +0200 | [diff] [blame] | 171 | Lock lock = channelLocks.get(channelId); |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 172 | lock.lock(); |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 173 | |
| 174 | try { |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 175 | if (!channels.containsKey(channelId)) { |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 176 | log.warn("Unknown channel ID '{}', can't check if channel is open", |
Carmelo Cascone | 47a853b | 2018-01-05 02:40:58 +0100 | [diff] [blame] | 177 | channelId); |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 178 | return false; |
| 179 | } |
| 180 | try { |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 181 | return doDummyMessage(channels.get(channelId)); |
| 182 | } catch (StatusRuntimeException e) { |
Carmelo Cascone | 47a853b | 2018-01-05 02:40:58 +0100 | [diff] [blame] | 183 | log.debug("Unable to send dummy message to {}: {}", |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 184 | channelId, e.toString()); |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 185 | return false; |
| 186 | } |
| 187 | } finally { |
| 188 | lock.unlock(); |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 192 | @Override |
| 193 | public void disconnectChannel(GrpcChannelId channelId) { |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 194 | checkNotNull(channelId); |
| 195 | |
Carmelo Cascone | 158b8c4 | 2018-07-04 19:42:37 +0200 | [diff] [blame] | 196 | Lock lock = channelLocks.get(channelId); |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 197 | lock.lock(); |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 198 | try { |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 199 | final ManagedChannel channel = channels.remove(channelId); |
Carmelo Cascone | a71b849 | 2018-12-17 17:47:50 -0800 | [diff] [blame^] | 200 | if (channel != null) { |
| 201 | shutdownNowAndWait(channel, channelId); |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 202 | } |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 203 | } finally { |
| 204 | lock.unlock(); |
| 205 | } |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Carmelo Cascone | a71b849 | 2018-12-17 17:47:50 -0800 | [diff] [blame^] | 208 | private void shutdownNowAndWait(ManagedChannel channel, GrpcChannelId channelId) { |
| 209 | try { |
| 210 | if (!channel.shutdownNow() |
| 211 | .awaitTermination(5, TimeUnit.SECONDS)) { |
| 212 | log.error("Channel '{}' didn't terminate, although we " + |
| 213 | "triggered a shutdown and waited", |
| 214 | channelId); |
| 215 | } |
| 216 | } catch (InterruptedException e) { |
| 217 | log.warn("Channel {} didn't shutdown in time", channelId); |
| 218 | Thread.currentThread().interrupt(); |
| 219 | } |
| 220 | } |
| 221 | |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 222 | @Override |
| 223 | public Map<GrpcChannelId, ManagedChannel> getChannels() { |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 224 | return ImmutableMap.copyOf(channels); |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public Collection<ManagedChannel> getChannels(final DeviceId deviceId) { |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 229 | checkNotNull(deviceId); |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 230 | final Set<ManagedChannel> deviceChannels = new HashSet<>(); |
| 231 | channels.forEach((k, v) -> { |
| 232 | if (k.deviceId().equals(deviceId)) { |
| 233 | deviceChannels.add(v); |
| 234 | } |
| 235 | }); |
| 236 | |
| 237 | return ImmutableSet.copyOf(deviceChannels); |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public Optional<ManagedChannel> getChannel(GrpcChannelId channelId) { |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 242 | checkNotNull(channelId); |
| 243 | |
Carmelo Cascone | 158b8c4 | 2018-07-04 19:42:37 +0200 | [diff] [blame] | 244 | Lock lock = channelLocks.get(channelId); |
Carmelo Cascone | fb92407 | 2017-08-29 20:21:55 +0200 | [diff] [blame] | 245 | lock.lock(); |
| 246 | |
| 247 | try { |
| 248 | return Optional.ofNullable(channels.get(channelId)); |
| 249 | } finally { |
| 250 | lock.unlock(); |
| 251 | } |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 252 | } |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 253 | |
| 254 | /** |
| 255 | * gRPC client interceptor that logs all messages sent and received. |
| 256 | */ |
| 257 | private final class InternalLogChannelInterceptor implements ClientInterceptor { |
| 258 | |
| 259 | private final GrpcChannelId channelId; |
| 260 | |
| 261 | private InternalLogChannelInterceptor(GrpcChannelId channelId) { |
| 262 | this.channelId = channelId; |
| 263 | } |
| 264 | |
| 265 | @Override |
Carmelo Cascone | 47a853b | 2018-01-05 02:40:58 +0100 | [diff] [blame] | 266 | public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( |
| 267 | MethodDescriptor<ReqT, RespT> methodDescriptor, |
| 268 | CallOptions callOptions, Channel channel) { |
| 269 | return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>( |
| 270 | channel.newCall(methodDescriptor, callOptions.withoutWaitForReady())) { |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 271 | |
| 272 | @Override |
| 273 | public void sendMessage(ReqT message) { |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 274 | if (enableMessageLog && !methodDescriptor.getFullMethodName() |
| 275 | .startsWith(SET_FORWARDING_PIPELINE_CONFIG_METHOD)) { |
| 276 | log.info("*** SENDING GRPC MESSAGE [{}]\n{}:\n{}", |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 277 | channelId, methodDescriptor.getFullMethodName(), |
| 278 | message.toString()); |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 279 | } |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 280 | super.sendMessage(message); |
| 281 | } |
| 282 | |
| 283 | @Override |
| 284 | public void start(Listener<RespT> responseListener, Metadata headers) { |
| 285 | |
| 286 | ClientCall.Listener<RespT> listener = new ForwardingClientCallListener<RespT>() { |
| 287 | @Override |
| 288 | protected Listener<RespT> delegate() { |
| 289 | return responseListener; |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void onMessage(RespT message) { |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 294 | if (enableMessageLog) { |
| 295 | log.info("*** RECEIVED GRPC MESSAGE [{}]\n{}:\n{}", |
Carmelo Cascone | 6d57f32 | 2018-12-13 23:15:17 -0800 | [diff] [blame] | 296 | channelId, methodDescriptor.getFullMethodName(), |
| 297 | message.toString()); |
Andrea Campanella | a74bdba | 2018-05-15 16:45:00 +0200 | [diff] [blame] | 298 | } |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 299 | super.onMessage(message); |
| 300 | } |
| 301 | }; |
| 302 | super.start(listener, headers); |
| 303 | } |
| 304 | }; |
| 305 | } |
| 306 | } |
Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame] | 307 | } |