Skip to content

Commit

Permalink
Merge pull request #46 from bosch-io/feature/policy-protocol
Browse files Browse the repository at this point in the history
Add basic level policy support to Ditto Java Client
  • Loading branch information
ffendt authored Mar 17, 2020
2 parents 4a300fc + 7cc1b8b commit 99d5a7a
Show file tree
Hide file tree
Showing 41 changed files with 2,451 additions and 236 deletions.
13 changes: 13 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ client.twin().create("org.eclipse.ditto:new-thing").handle((createdThing, throwa
}).get(); // this will block the thread! work asynchronously whenever possible!
```

#### Manage policies

```java
client.policies().create(newPolicy)
.thenAccept(createdPolicy -> System.out.println("Created new Policy: " + createdPolicy)).get();

client.twin()
.forId(ThingId.of("org.eclipse.ditto:new-thing"))
.setPolicyId(newPolicy.getEntityId().get())
.thenAccept(_void -> System.out.println("PolicyId was adapted"))
.get();
```

#### Subscribe for change notifications

```java
Expand Down
1 change: 1 addition & 0 deletions java/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<include>org.eclipse.ditto:ditto-signals-base</include>
<include>org.eclipse.ditto:ditto-signals-commands-base</include>
<include>org.eclipse.ditto:ditto-signals-commands-things</include>
<include>org.eclipse.ditto:ditto-signals-commands-policies</include>
<include>org.eclipse.ditto:ditto-signals-commands-messages</include>
<include>org.eclipse.ditto:ditto-signals-commands-live</include>
<include>org.eclipse.ditto:ditto-signals-events-base</include>
Expand Down
9 changes: 9 additions & 0 deletions java/src/main/java/org/eclipse/ditto/client/DittoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.concurrent.CompletableFuture;

import org.eclipse.ditto.client.live.Live;
import org.eclipse.ditto.client.policies.Policies;
import org.eclipse.ditto.client.twin.Twin;
import org.eclipse.ditto.protocoladapter.Adaptable;

Expand Down Expand Up @@ -56,4 +57,12 @@ public interface DittoClient {
*/
CompletableFuture<Adaptable> sendDittoProtocol(Adaptable dittoProtocolAdaptable);

/**
* Returns the client's {@link Policies} singleton which provides the necessary functionality to manage and monitor
* {@link org.eclipse.ditto.model.policies.Policy}s.
*
* @return the Policy handle
* @since 1.1.0
*/
Policies policies();
}
48 changes: 43 additions & 5 deletions java/src/main/java/org/eclipse/ditto/client/DittoClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,28 @@ public static DittoClient newInstance(final MessagingProvider messagingProvider)
public static DittoClient newInstance(final MessagingProvider twinMessagingProvider,
final MessagingProvider liveMessagingProvider) {

final ResponseForwarder responseForwarder = ResponseForwarder.getInstance();
return newInstance(twinMessagingProvider, liveMessagingProvider, twinMessagingProvider);
}

/**
* Creates a new {@link org.eclipse.ditto.client.DittoClient} with a specific {@code Twin} and {@code Live}
* {@link org.eclipse.ditto.client.messaging.MessagingProvider}.
*
* @param twinMessagingProvider the messaging provider for the {@code Twin} part of the client.
* @param liveMessagingProvider the messaging provider for the {@code Live} part of the client.
* @param policyMessagingProvider the messaging provider for the {@code Policy} part of the client.
* @return the client.
* @throws org.eclipse.ditto.client.messaging.AuthenticationException if authentication failed.
* @throws org.eclipse.ditto.client.messaging.MessagingException if a connection to the configured endpoint
* could not be established
* @since 1.1.0
*/
public static DittoClient newInstance(final MessagingProvider twinMessagingProvider,
final MessagingProvider liveMessagingProvider, final MessagingProvider policyMessagingProvider) {

final MessageSerializerRegistry messageSerializerRegistry =
MessageSerializerFactory.newInstance().getMessageSerializerRegistry();
return DefaultDittoClient.newInstance(twinMessagingProvider, liveMessagingProvider, responseForwarder,
messageSerializerRegistry);
return newInstance(twinMessagingProvider, liveMessagingProvider, policyMessagingProvider, messageSerializerRegistry);
}

/**
Expand All @@ -88,9 +105,30 @@ public static DittoClient newInstance(final MessagingProvider twinMessagingProvi
public static DittoClient newInstance(final MessagingProvider twinMessagingProvider,
final MessagingProvider liveMessagingProvider, final MessageSerializerRegistry messageSerializerRegistry) {

return newInstance(twinMessagingProvider, liveMessagingProvider, twinMessagingProvider, messageSerializerRegistry);
}

/**
* Creates a new {@link org.eclipse.ditto.client.DittoClient} with a specific {@code Twin}, {@code Live} and
* {@code Policy} {@link org.eclipse.ditto.client.messaging.MessagingProvider}.
*
* @param twinMessagingProvider the messaging provider for the {@code Twin} part of the client.
* @param liveMessagingProvider the messaging provider for the {@code Live} part of the client.
* @param policyMessagingProvider the messaging provider for the {@code Policy} part of the client.
* @param messageSerializerRegistry a registry of {@code MessageSerializer}s for the {@code Live} part of the client.
* @return the client.
* @throws org.eclipse.ditto.client.messaging.AuthenticationException if authentication failed.
* @throws org.eclipse.ditto.client.messaging.MessagingException if a connection to the configured endpoint
* could not be established
* @since 1.1.0
*/
public static DittoClient newInstance(final MessagingProvider twinMessagingProvider,
final MessagingProvider liveMessagingProvider, final MessagingProvider policyMessagingProvider,
final MessageSerializerRegistry messageSerializerRegistry) {

final ResponseForwarder responseForwarder = ResponseForwarder.getInstance();
return DefaultDittoClient.newInstance(twinMessagingProvider, liveMessagingProvider, responseForwarder,
messageSerializerRegistry);
return DefaultDittoClient.newInstance(twinMessagingProvider, liveMessagingProvider, policyMessagingProvider,
responseForwarder, messageSerializerRegistry);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static final class WebSocketMessagingConfigurationBuilder implements Mes
private boolean reconnectEnabled = true;
private ProxyConfiguration proxyConfiguration;
private TrustStoreConfiguration trustStoreConfiguration;

@Override
public MessagingConfiguration.Builder jsonSchemaVersion(final JsonSchemaVersion jsonSchemaVersion) {
this.jsonSchemaVersion = checkNotNull(jsonSchemaVersion, "jsonSchemaVersion");
Expand Down
Loading

0 comments on commit 99d5a7a

Please sign in to comment.