-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
005be27
commit 3b6f21d
Showing
13 changed files
with
405 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
classdef LAPISData < handle | ||
% LAPIS data object. This object must be used if publishing a variable | ||
% to a LAPIS network. The object has two fields: data and name. In | ||
% order to access the data or set the data to this object, the "data" | ||
% field must be used. | ||
% EXAMPLE: | ||
% x = LAPISData('x', [1 2 3 4 5]); | ||
% x.data = [5 6 7 8 9]; | ||
% y = x.data; | ||
|
||
properties | ||
name; %Name of the variable on the LAPIS network. Used by other nodes to get and set data | ||
data; %Data of the variable | ||
lapReference; | ||
end | ||
|
||
methods | ||
|
||
function obj = LAPISData(name, data) | ||
%Constructor. args(name, data) | ||
obj.name = name; | ||
obj.data = data; | ||
end | ||
|
||
function obj = set.data(obj, value) | ||
% Setter for data property. | ||
try | ||
obj.lapReference.setCachedValue(obj.name, value); | ||
obj.data = value; | ||
catch e | ||
% warning('Value was not set in LAPIS'); | ||
obj.data = value; | ||
end | ||
|
||
end | ||
|
||
function result = get.data(obj) | ||
% Getter for the data property | ||
try | ||
result = obj.lapReference.retrieveCachedValue(obj.name); | ||
catch e | ||
warning('Value not retrieved from cache. This is normal when a variable is first published.'); | ||
result = obj.data; | ||
end | ||
end | ||
|
||
|
||
function obj = setLapisReference(obj, lap) | ||
% Sets the LAPIS reference in order to connect the reference to to a lapis network | ||
obj.lapReference = lap; | ||
end | ||
|
||
function result = display(obj) | ||
% Overridden display method for object | ||
disp(' '); | ||
disp('LAPISData Object : '); | ||
display(obj.data); | ||
end | ||
|
||
function result = length(obj) | ||
%Returns length of the data in the object | ||
result = length(obj.data); | ||
|
||
end | ||
|
||
function result = size(obj) | ||
%Returns size of the data in the object | ||
result = size(obj.data); | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
classdef LapisAPI < handle | ||
% LAPIS API object. Responsible for connecting and maintaing a LAPIS | ||
% network connection. Use this API to do SETs and GETs on a LAPIS | ||
% network. Depends on a LAPIS java JAR file. | ||
% EXAMPLE: | ||
% coordinatorAddress = 'http://127.0.0.1:7777'; | ||
% nodeName = 'Node1'; | ||
% lap = LapisAPI(nodeName, coordinatorAddress); | ||
|
||
|
||
|
||
properties | ||
|
||
dataTable; %Datatable for local published variables | ||
lapisJava; %Java LAPIS API | ||
modelName; %Name of model | ||
coordinatorAddress; %Coordinator address | ||
modelAddress; %Model port and address | ||
isCoordinator; %Status of coordinator | ||
end | ||
|
||
|
||
methods | ||
|
||
function obj = LapisAPI(varargin) | ||
%Constructor. If model is coordinator, use: Args(modelName, coordinatorAddress). If model is not coordinator, use Args(modelName, coordinatorAddress, modelAddress) | ||
|
||
obj.dataTable = containers.Map; | ||
|
||
% set up logging | ||
java.lang.System.setProperty('line.separator',char(10)); %prevents double-spacing of log output | ||
org.apache.log4j.helpers.LogLog.setInternalDebugging(1); | ||
org.apache.log4j.PropertyConfigurator.configure([pwd char(java.lang.System.getProperty('file.separator')) 'log4j.properties']); | ||
org.apache.log4j.helpers.LogLog.setInternalDebugging(0); | ||
|
||
import edu.osu.lapis.MatlabLapis; | ||
|
||
if nargin == 2 %Model is the coordinator | ||
obj.modelName = varargin{1}; | ||
obj.coordinatorAddress = varargin{2}; | ||
obj.modelAddress = obj.coordinatorAddress; | ||
obj.isCoordinator = true; | ||
|
||
obj.lapisJava = MatlabLapis(java.lang.String(obj.modelName), ... | ||
java.lang.String(obj.coordinatorAddress)); | ||
|
||
elseif nargin == 3 %Model is not coordinator | ||
obj.modelName = varargin{1}; | ||
obj.coordinatorAddress = varargin{2}; | ||
obj.modelAddress = varargin{3}; | ||
obj.isCoordinator = false; | ||
|
||
obj.lapisJava = MatlabLapis(java.lang.String(obj.modelName), ... | ||
java.lang.String(obj.coordinatorAddress), ... | ||
java.lang.String(obj.modelAddress)); | ||
else | ||
error('There is no Constructor signature with the specified number of parameters'); | ||
end | ||
end | ||
|
||
|
||
function obj = publish(obj, data) | ||
%Publishes a variable. Args(variableName, LapisDataObject). | ||
|
||
if ~isa(data, 'LAPISData') | ||
error('Published datatype must be type "LAPISData"'); | ||
end | ||
|
||
data.setLapisReference(obj); | ||
|
||
obj.dataTable(data.name) = data; | ||
obj.lapisJava.publish(java.lang.String(data.name), data.data); | ||
end | ||
|
||
function obj = redact(obj, data) | ||
% un-publish a varible | ||
obj.lapisJava.redact(data.name) | ||
end | ||
|
||
function obj = setCachedValue(obj, varName, data) | ||
% Setter to put a value into the LAPIS cache | ||
obj.lapisJava.setCachedValue(varName, data); | ||
end | ||
|
||
function result = retrieveCachedValue(obj, varName) | ||
% Getter method to get a value from the LAPIS cache | ||
result = obj.lapisJava.retrieveCachedValue(varName); | ||
end | ||
|
||
function obj = delete(obj) | ||
%Deletes the object. | ||
obj.shutdown; | ||
end | ||
|
||
function obj = set(obj,modelName, varName, data) | ||
%Sets a variable on another LAPIS node. Args(modelName, variablename, data) | ||
|
||
if ~isa(data, 'double') | ||
error('Setting types other than doubles are not currently supported'); | ||
end | ||
|
||
fullName = [varName '@' modelName]; | ||
obj.lapisJava.set(fullName, data); | ||
|
||
end | ||
|
||
function result = get(obj, modelName, varName) | ||
%Gets a variable on another LAPIS node. Args(modelName, variablename, data) | ||
fullName = [varName '@' modelName]; | ||
try | ||
result = obj.lapisJava.get(java.lang.String(fullName)); | ||
catch e | ||
disp('There was an error getting the value. Please try again.'); | ||
result = obj.lapisJava.get(java.lang.String(fullName)); | ||
end | ||
end | ||
|
||
function obj = shutdown(obj) | ||
%Shuts down the LAPIS nework. This step is required if clearing variables. | ||
obj.lapisJava.shutdown(); | ||
end | ||
|
||
function obj = ready(obj) | ||
%ready | ||
% declares that this LAPIS node is now ready | ||
% | ||
% The functions ready, notReady, waitForReadyNode, and | ||
% waitForReadyNodeWithTimeout facilitate coordination among | ||
% multiple nodes in a LAPIS network. It is not necessary for a | ||
% node to declare that it is ready by using the ready function | ||
% unless other nodes on the same network are or will be waiting | ||
% for the node to become ready using either the waitForReadyNode | ||
% or the waitForReadyNodeWithTimeout functions. | ||
obj.lapisJava.ready(); | ||
end | ||
|
||
function obj = notReady(obj) | ||
%notReady | ||
% declares that this LAPIS node is not ready | ||
% | ||
% The functions ready, notReady, waitForReadyNode, and | ||
% waitForReadyNodeWithTimeout facilitate coordination among | ||
% multiple nodes in a LAPIS network. | ||
obj.lapisJava.notReady(); | ||
end | ||
|
||
function obj = waitForReadyNode(obj, nodeName) | ||
%waitForReadyNode | ||
% waitForReadyNode(N) waits indefinitely for node N to become | ||
% 'ready' and does not time out | ||
obj.lapisJava.waitForReadyNode(nodeName); | ||
end | ||
|
||
function obj = waitForReadyNodeWithTimeout(obj, nodeName, millisToWait) | ||
%waitForReadyNodeWithTimeout | ||
% waitForReadyNodeWithTimeout(N, M) waits for node N to become | ||
% 'ready' and times out with an exception after M milliseconds if | ||
% node N has not become ready | ||
|
||
obj.lapisJava.waitForReadyNode(nodeName, millisToWait); | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
log4j.rootLogger=INFO, stdout | ||
|
||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
|
||
# don't use %n in layout -- MATLAB prints two lines for this | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c %x - %m\n | ||
|
||
|
||
log4j.logger.LogService=WARN | ||
log4j.logger.org.restlet=WARN | ||
log4j.logger.org.restlet.Component.Server=WARN | ||
|
||
log4j.logger.edu.osu.lapis=INFO | ||
log4j.logger.edu.osu.lapis.comm.client.LapisNetworkClient=INFO | ||
log4j.logger.edu.osu.lapis.comm.Notifier=INFO | ||
log4j.logger.edu.osu.lapis.network.NetworkTable=INFO | ||
log4j.logger.edu.osu.lapis.restlets.VariableMetaDataApiRestlet=WARN | ||
log4j.logger.edu.osu.lapis.transmission.LapisNetworkTransmission=INFO | ||
log4j.logger.edu.osu.lapis.transmission.LapisTransmission=INFO | ||
|
Oops, something went wrong.