Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions sdk/src/main/java/io/dapr/actors/DaprClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
*/
class DaprClientBuilder {

/**
* Default hostname for Dapr.
*/
private String hostname = Constants.DEFAULT_HOSTNAME;

/**
* Default port for Dapr after checking environment variable.
*/
Expand All @@ -29,18 +24,7 @@ class DaprClientBuilder {
public DaprAsyncClient buildAsyncClient() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
// TODO: Expose configurations for OkHttpClient or com.microsoft.rest.RestClient.
String baseUrl = String.format("http://%s:%d/", this.hostname, this.port);
return new DaprHttpAsyncClient(baseUrl, builder.build());
}

/**
* Overrides the hostname.
* @param hostname new hostname.
* @return This instance.
*/
public DaprClientBuilder withHostname(String hostname) {
this.hostname = hostname;
return this;
return new DaprHttpAsyncClient(this.port, builder.build());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/main/java/io/dapr/actors/DaprHttpAsyncClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class DaprHttpAsyncClient implements DaprAsyncClient {

/**
* Creates a new instance of {@link DaprHttpAsyncClient}.
* @param baseUrl Base Url for calling Dapr. (e.g. http://localhost:3500/)
* @param port Port for calling Dapr. (e.g. 3500)
* @param httpClient RestClient used for all API calls in this new instance.
*/
DaprHttpAsyncClient(String baseUrl, OkHttpClient httpClient)
DaprHttpAsyncClient(int port, OkHttpClient httpClient)
{
this.baseUrl = baseUrl;
this.baseUrl = String.format("http://%s:%d/", Constants.DEFAULT_HOSTNAME, port);;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra ;

this.httpClient = httpClient;
}

Expand Down
27 changes: 27 additions & 0 deletions sdk/src/main/java/io/dapr/actors/runtime/ActorCallType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*/

package io.dapr.actors.runtime;

/**
* Represents the call-type associated with the method invoked by actor runtime.
*/
enum ActorCallType {

/**
* Specifies that the method invoked is an actor interface method for a given client request.
*/
ACTOR_INTERFACE_METHOD,

/**
* Specifies that the method invoked is a timer callback method.
*/
TIMER_METHOD,

/**
* Specifies that the method is when a reminder fires.
*/
REMINDER_METHOD
}
78 changes: 78 additions & 0 deletions sdk/src/main/java/io/dapr/actors/runtime/ActorMethodContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*/

package io.dapr.actors.runtime;

/**
* Contains information about the method that is invoked by actor runtime.
*/
class ActorMethodContext {

/**
* Method name to be invoked.
*/
private final String methodName;

/**
* Call type to be used.
*/
private final ActorCallType callType;

/**
* Constructs a new instance of {@link ActorMethodContext}
* @param methodName Method name to be invoked.
* @param callType Call type to be used.
*/
private ActorMethodContext(String methodName, ActorCallType callType) {
this.methodName = methodName;
this.callType = callType;
}

/**
* Gets the name of the method invoked by actor runtime.
* @return The method name.
*/
public String getMethodName() {
return this.methodName;
}

/**
* Gets the call type to be used.
* @return Call type.
*/
public ActorCallType getCallType() {
return this.callType;
}

/**
* Creates a context to invoke an Actor's method.
* @param methodName THe method to be invoked.
* @return Context of the method call as {@link ActorMethodContext}
*/
static ActorMethodContext CreateForActor(String methodName)
{
return new ActorMethodContext(methodName, ActorCallType.ACTOR_INTERFACE_METHOD);
}

/**
* Creates a context to invoke an Actor's timer.
* @param methodName THe method to be invoked.
* @return Context of the method call as {@link ActorMethodContext}
*/
static ActorMethodContext CreateForTimer(String methodName)
{
return new ActorMethodContext(methodName, ActorCallType.TIMER_METHOD);
}

/**
* Creates a context to invoke an Actor's reminder.
* @param methodName THe method to be invoked.
* @return Context of the method call as {@link ActorMethodContext}
*/
static ActorMethodContext CreateForReminder(String methodName)
{
return new ActorMethodContext(methodName, ActorCallType.REMINDER_METHOD);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*/

package io.dapr.actors.runtime;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
* Serializes and deserializes an object.
*/
class ActorStateProviderSerializer {

/**
* Shared Json serializer/deserializer as per Jackson's documentation.
*/
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

/**
* Serializes a given state object into byte array.
* @param state State object to be serialized.
* @return Array of bytes[] with the serialized content.
* @throws IOException
*/
byte[] serialize(Object state) throws IOException {
return OBJECT_MAPPER.writeValueAsBytes(state);
}

/**
* Deserializes the byte array into the original object.
* @param buffer Array of bytes to be parsed.
* @param clazz Type of the object being deserialized.
* @param <T> Generic type of the object being deserialized.
* @return Object of type T.
* @throws IOException
*/
<T> T deserialize(byte[] buffer, Class<T> clazz) throws IOException {
return OBJECT_MAPPER.readValue(buffer, clazz);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Contains the information about the class implementing an actor.
*/
public final class ActorTypeInformation {
final class ActorTypeInformation {

/**
* Actor type's name.
Expand Down