Skip to content

Commit f87d508

Browse files
NiteshKantstevegury
authored andcommitted
Extract interface Availability (#191)
* Extract interface `AvailabilityProvider` #### Problem `DuplexConnection`, `ReactiveSocket` and `ReactiveSocketClient` all provide a method `double availability()` and so can benefit from having a common interface. This will be useful for giving event callbacks that retrieve availability as availability follows a pull model instead of push. #### Modification Added a new interface `AvailabilityProvider` and have the other interfaces extend it. #### Result Common way to access availabilty. * Rename `AvailabilityProvider` to `Availability`
1 parent 5c6dd9b commit f87d508

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2016 Netflix, Inc.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivesocket;
15+
16+
public interface Availability {
17+
18+
/**
19+
* @return a positive numbers representing the availability of the entity.
20+
* Higher is better, 0.0 means not available
21+
*/
22+
double availability();
23+
24+
}

reactivesocket-core/src/main/java/io/reactivesocket/DuplexConnection.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Represents a connection with input/output that the protocol uses.
2626
*/
27-
public interface DuplexConnection {
27+
public interface DuplexConnection extends Availability {
2828

2929
/**
3030
* Sends the source of {@link Frame}s on this connection and returns the {@code Publisher} representing the result
@@ -77,12 +77,6 @@ default Publisher<Void> sendOne(Frame frame) {
7777
*/
7878
Publisher<Frame> receive();
7979

80-
/**
81-
* @return the availability of the underlying connection, a number in [0.0, 1.0]
82-
* (higher is better).
83-
*/
84-
double availability();
85-
8680
/**
8781
* Close this {@code DuplexConnection} upon subscribing to the returned {@code Publisher}
8882
*

reactivesocket-core/src/main/java/io/reactivesocket/ReactiveSocket.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
package io.reactivesocket;
1818

1919
import org.reactivestreams.Publisher;
20-
import io.reactivesocket.reactivestreams.extensions.Px;
2120

2221
/**
2322
* A contract providing different interaction models for <a href="https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md">ReactiveSocket protocol</a>.
2423
*/
25-
public interface ReactiveSocket {
24+
public interface ReactiveSocket extends Availability {
2625

2726
/**
2827
* Fire and Forget interaction model of {@code ReactiveSocket}.
@@ -71,11 +70,7 @@ public interface ReactiveSocket {
7170
*/
7271
Publisher<Void> metadataPush(Payload payload);
7372

74-
/**
75-
* Client check for availability to send request based on lease
76-
*
77-
* @return 0.0 to 1.0 indicating availability of sending requests
78-
*/
73+
@Override
7974
default double availability() {
8075
return 0.0;
8176
}

reactivesocket-core/src/main/java/io/reactivesocket/client/ReactiveSocketClient.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
package io.reactivesocket.client;
1818

1919
import io.reactivesocket.AbstractReactiveSocket;
20+
import io.reactivesocket.Availability;
2021
import io.reactivesocket.ReactiveSocket;
2122
import io.reactivesocket.lease.DisabledLeaseAcceptingSocket;
2223
import io.reactivesocket.lease.LeaseEnforcingSocket;
2324
import io.reactivesocket.transport.TransportClient;
2425
import org.reactivestreams.Publisher;
2526

26-
import java.util.function.Function;
27-
28-
public interface ReactiveSocketClient {
27+
public interface ReactiveSocketClient extends Availability {
2928

3029
/**
3130
* Creates a new {@code ReactiveSocket} every time the returned {@code Publisher} is subscribed.
@@ -34,12 +33,6 @@ public interface ReactiveSocketClient {
3433
*/
3534
Publisher<? extends ReactiveSocket> connect();
3635

37-
/**
38-
* @return a positive numbers representing the availability of the factory.
39-
* Higher is better, 0.0 means not available
40-
*/
41-
double availability();
42-
4336
/**
4437
* Creates a new instances of {@code ReactiveSocketClient} using the passed {@code transportClient}. This client
4538
* will not accept any requests from the server, so the client is half duplex. To create full duplex clients use

0 commit comments

Comments
 (0)