Skip to content

Commit

Permalink
Reformatting with google-java-format
Browse files Browse the repository at this point in the history
  • Loading branch information
emichael committed Nov 20, 2023
1 parent 11f07d1 commit aa70847
Show file tree
Hide file tree
Showing 133 changed files with 15,371 additions and 15,838 deletions.
102 changes: 52 additions & 50 deletions framework/src/dslabs/framework/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,70 +33,72 @@
import org.apache.commons.lang3.builder.CompareToBuilder;

/**
* Addresses are opaque objects that uniquely identify {@link Node}s. While the
* provided addresses might provide meaningful information via {@link
* Object#toString()}, you should not use those {@link String}s (except when
* printing addresses). Instead, use {@link Object#equals(Object)} and {@link
* #compareTo(Object)} to compare addresses.
* Addresses are opaque objects that uniquely identify {@link Node}s. While the provided addresses
* might provide meaningful information via {@link Object#toString()}, you should not use those
* {@link String}s (except when printing addresses). Instead, use {@link Object#equals(Object)} and
* {@link #compareTo(Object)} to compare addresses.
*/
public interface Address extends Serializable, Comparable<Address> {

// TODO: call root address everywhere in test framework
// TODO: call root address everywhere in test framework

/**
* Returns the root address, representing the root {@link Node} of some
* hierarchy.
*
* @return the root address
*/
default Address rootAddress() {
return this;
}
/**
* Returns the root address, representing the root {@link Node} of some hierarchy.
*
* @return the root address
*/
default Address rootAddress() {
return this;
}

/**
* Returns a sub-address for the given address. Used to initialize a
* sub-node.
*
* @param address
* the address of the parent node
* @param id
* the sub-node's identifier
* @return the sub-address.
*/
static Address subAddress(Address address, String id) {
return new SubAddress(address, id);
}
/**
* Returns a sub-address for the given address. Used to initialize a sub-node.
*
* @param address the address of the parent node
* @param id the sub-node's identifier
* @return the sub-address.
*/
static Address subAddress(Address address, String id) {
return new SubAddress(address, id);
}
}

@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
@EqualsAndHashCode
class SubAddress implements Address {
@Getter(AccessLevel.PACKAGE) @NonNull private final Address parentAddress;
@Getter(AccessLevel.PACKAGE) @NonNull private final String id;
@Getter(AccessLevel.PACKAGE)
@NonNull
private final Address parentAddress;

@Override
public int compareTo(@Nonnull Address o) {
// TODO: check this method
@Getter(AccessLevel.PACKAGE)
@NonNull
private final String id;

if (!(o instanceof SubAddress)) {
if (Objects.equals(parentAddress, o)) {
return -1;
}
return parentAddress.compareTo(o);
}
@Override
public int compareTo(@Nonnull Address o) {
// TODO: check this method

SubAddress sa = (SubAddress) o;
return new CompareToBuilder().append(parentAddress, sa.parentAddress)
.append(id, sa.id).toComparison();
if (!(o instanceof SubAddress)) {
if (Objects.equals(parentAddress, o)) {
return -1;
}
return parentAddress.compareTo(o);
}

@Override
public String toString() {
return String.format("%s/%s", parentAddress, id);
}
SubAddress sa = (SubAddress) o;
return new CompareToBuilder()
.append(parentAddress, sa.parentAddress)
.append(id, sa.id)
.toComparison();
}

@Override
public Address rootAddress() {
return parentAddress.rootAddress();
}
@Override
public String toString() {
return String.format("%s/%s", parentAddress, id);
}

@Override
public Address rootAddress() {
return parentAddress.rootAddress();
}
}
28 changes: 12 additions & 16 deletions framework/src/dslabs/framework/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,19 @@
import java.io.Serializable;

/**
* <p>Applications are simple data structures used by your {@link Node}s.
* Applications are simple data structures used by your {@link Node}s.
*
* <p>Applications need not support concurrent access. However, to work with
* the distributed systems you create, they must be deterministic.
* <p>Applications need not support concurrent access. However, to work with the distributed systems
* you create, they must be deterministic.
*/
public interface Application extends Serializable {
/**
* Execute the given command for the application and return the result. If
* the application cannot handle the command, it should throw an
* {@link IllegalArgumentException}.
*
* @param command
* the command to execute
* @return the result
*
* @throws IllegalArgumentException
* if the application cannot handle the command type
*/
Result execute(Command command) throws IllegalArgumentException;
/**
* Execute the given command for the application and return the result. If the application cannot
* handle the command, it should throw an {@link IllegalArgumentException}.
*
* @param command the command to execute
* @return the result
* @throws IllegalArgumentException if the application cannot handle the command type
*/
Result execute(Command command) throws IllegalArgumentException;
}
89 changes: 39 additions & 50 deletions framework/src/dslabs/framework/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,50 @@
package dslabs.framework;

/**
* <p>Clients are a special case of {@link Node}. Client nodes will have
* handlers for {@link Message}s and {@link Timer}s like all {@link Node}s but
* also provide an interface for interactively sending {@link Command}s and
* receiving {@link Result}s in a system.
* Clients are a special case of {@link Node}. Client nodes will have handlers for {@link Message}s
* and {@link Timer}s like all {@link Node}s but also provide an interface for interactively sending
* {@link Command}s and receiving {@link Result}s in a system.
*
* <p>Clients in this framework are "closed-loop" clients. That is, they will
* only have one outstanding command at any given time. You are free to assume
* this throughout the labs; the test code always waits for the previous command
* to return a result before sending the next.
* <p>Clients in this framework are "closed-loop" clients. That is, they will only have one
* outstanding command at any given time. You are free to assume this throughout the labs; the test
* code always waits for the previous command to return a result before sending the next.
*
* <p><b>IMPORTANT:</b> Client interface methods must be properly {@code
* synchronized} with {@link Message} handlers and {@link Timer} handlers, since
* the event handlers are invoked concurrently with the code using the client.
* The easiest way to do this is to add the {@code synchronized} modifier to all
* of the aforementioned methods. Furthermore, {@link Client#hasResult()} should
* return immediately, while {@link Client#getResult()} should block until the
* client has received a result for the latest command it sent.
* <p><b>IMPORTANT:</b> Client interface methods must be properly {@code synchronized} with {@link
* Message} handlers and {@link Timer} handlers, since the event handlers are invoked concurrently
* with the code using the client. The easiest way to do this is to add the {@code synchronized}
* modifier to all of the aforementioned methods. Furthermore, {@link Client#hasResult()} should
* return immediately, while {@link Client#getResult()} should block until the client has received a
* result for the latest command it sent.
*/
public interface Client {

/**
* Send a {@link Command} to the system with the given operation. Should
* send the {@link Command} and return immediately without blocking,
* sleeping, or starting other threads.
*
* @param command
* the {@link Application} command to send
*/
void sendCommand(Command command);
/**
* Send a {@link Command} to the system with the given operation. Should send the {@link Command}
* and return immediately without blocking, sleeping, or starting other threads.
*
* @param command the {@link Application} command to send
*/
void sendCommand(Command command);

/**
* Whether or not a {@link Result} was received for the previously sent
* {@link Command}. Should return immediately without blocking, sleeping, or
* starting other threads.
*
* @return whether the {@link Result} has been received
*/
boolean hasResult();
/**
* Whether or not a {@link Result} was received for the previously sent {@link Command}. Should
* return immediately without blocking, sleeping, or starting other threads.
*
* @return whether the {@link Result} has been received
*/
boolean hasResult();

/**
* <p>Returns the value from the {@link Result} for the previously sent
* {@link Command}. Should block until there is such a {@link Result} or the
* waiting thread is interrupted; this of course means that this method
* should relinquish all locks/monitors it holds preventing messages from
* being received while it is waiting. If the calling thread is interrupted
* while waiting for a {@link Result}, an {@link InterruptedException}
* should be thrown. Successive calls to this method (and {@link
* Client#hasResult()}) that are not interrupted and are not interleaved
* with calls to {@link Client#sendCommand(Command)} should continue to
* return the same value.
*
* @return the value corresponding to the previously sent {@link Command}
*
* @throws InterruptedException
* when the calling thread is interrupted while blocking
*/
Result getResult() throws InterruptedException;
/**
* Returns the value from the {@link Result} for the previously sent {@link Command}. Should block
* until there is such a {@link Result} or the waiting thread is interrupted; this of course means
* that this method should relinquish all locks/monitors it holds preventing messages from being
* received while it is waiting. If the calling thread is interrupted while waiting for a {@link
* Result}, an {@link InterruptedException} should be thrown. Successive calls to this method (and
* {@link Client#hasResult()}) that are not interrupted and are not interleaved with calls to
* {@link Client#sendCommand(Command)} should continue to return the same value.
*
* @return the value corresponding to the previously sent {@link Command}
* @throws InterruptedException when the calling thread is interrupted while blocking
*/
Result getResult() throws InterruptedException;
}
16 changes: 7 additions & 9 deletions framework/src/dslabs/framework/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@

import java.io.Serializable;

/**
* An operation on an {@link Application}.
*/
/** An operation on an {@link Application}. */
public interface Command extends Serializable {

/**
* @return whether or not the command changes the application's state
*/
default boolean readOnly() {
return false;
}
/**
* @return whether or not the command changes the application's state
*/
default boolean readOnly() {
return false;
}
}
11 changes: 5 additions & 6 deletions framework/src/dslabs/framework/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
import java.io.Serializable;

/**
* <p>Base interface for all messages in the system. You will need to create
* implementers of Message to define various types of messages in your system.
* Base interface for all messages in the system. You will need to create implementers of Message to
* define various types of messages in your system.
*
* <p>All messages must properly implement {@link Object#equals(Object)},
* {@link Object#hashCode()}, and {@link Object#toString()}.
* <p>All messages must properly implement {@link Object#equals(Object)}, {@link Object#hashCode()},
* and {@link Object#toString()}.
*/
public interface Message extends Serializable {
}
public interface Message extends Serializable {}
Loading

0 comments on commit aa70847

Please sign in to comment.