Skip to content

Commit

Permalink
Prepping for tag 0.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmalone committed Jan 6, 2014
1 parent 005be27 commit 3b6f21d
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lapis-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>edu.osu.lapis</groupId>
<artifactId>lapis-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.3</version>
</parent>

<artifactId>lapis-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion lapis-java-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>edu.osu.lapis</groupId>
<artifactId>lapis-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.3</version>
</parent>

<artifactId>lapis-java-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion lapis-matlab/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>edu.osu.lapis</groupId>
<artifactId>lapis-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.3</version>
</parent>

<artifactId>lapis-matlab</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion lapis-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>edu.osu.lapis</groupId>
<artifactId>lapis-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.3</version>
<packaging>pom</packaging>

<name>lapis-parent</name>
Expand Down
8 changes: 4 additions & 4 deletions matlab-files/LapisAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
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)
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;

Expand Down
8 changes: 1 addition & 7 deletions matlab-files/node1simulation.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

%YOU MUST RUN THIS FILE BEFORE RUNNING node2simulation.m

% NOTE FOR LOGGING (optional):
% the following two lines from $matlabroot/toolbox/local/classpath.txt must be commented out (or logging won't work...it will give a WARN)
% #$matlabroot/java/jarext/jxbrowser/slf4j-api.jar
% #$matlabroot/java/jarext/jxbrowser/slf4j-log4j12.jar


clear all
clear classes
clear java
javaaddpath([pwd '\lapis-matlab-1.0-SNAPSHOT-jar-with-dependencies.jar']); %add the lapis jar file. Future releases will include this in the LapisAPI class.
javaaddpath([pwd '\lapis-matlab-0.3-jar-with-dependencies.jar']); %add the lapis jar file. Future releases will include this in the LapisAPI class.

%% set up LAPIS
coordinatorAddress = 'http://127.0.0.1:7777';
Expand Down
2 changes: 1 addition & 1 deletion matlab-files/node2simulation.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
clear all
clear classes
clear java
javaaddpath([pwd '\lapis-matlab-1.0-SNAPSHOT-jar-with-dependencies.jar']); %add the lapis jar file. Future releases will include this in the LapisAPI class.
javaaddpath([pwd '\lapis-matlab-0.3-jar-with-dependencies.jar']); %add the lapis jar file. Future releases will include this in the LapisAPI class.


%% set up LAPIS
Expand Down
20 changes: 0 additions & 20 deletions matlab-files/node3.m

This file was deleted.

74 changes: 74 additions & 0 deletions tag/0.3/LAPISData.m
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
165 changes: 165 additions & 0 deletions tag/0.3/LapisAPI.m
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
21 changes: 21 additions & 0 deletions tag/0.3/log4j.properties
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

Loading

0 comments on commit 3b6f21d

Please sign in to comment.