Skip to content

Commit

Permalink
Merge pull request #1 from pcginc/master
Browse files Browse the repository at this point in the history
Updated README's and pointed to correct source code
  • Loading branch information
nathantippy authored Jan 17, 2018
2 parents 28fc7bb + a47d550 commit 9e50978
Show file tree
Hide file tree
Showing 20 changed files with 812 additions and 483 deletions.
8 changes: 4 additions & 4 deletions GenREADME.txt → GenREADME.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
for dir in */
do
echo $dir
( cd $dir && bash includeFile gen.md>README.md )
for dir in */
do
echo $dir
( cd $dir && bash includeFile gen.md>README.md )
done
131 changes: 88 additions & 43 deletions HTTPClient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,40 @@
Demo code:

```java
package com.ociweb.oe.floglight.api;
package com.ociweb.oe.greenlightning.api;


import com.ociweb.iot.maker.FogApp;
import com.ociweb.iot.maker.FogRuntime;
import com.ociweb.iot.maker.Hardware;
import com.ociweb.gl.api.Builder;
import com.ociweb.gl.api.GreenApp;
import com.ociweb.gl.api.GreenRuntime;
import com.ociweb.gl.api.HTTPSession;

public class HTTPClient implements FogApp
public class HTTPClient implements GreenApp
{

@Override
public void declareConnections(Hardware c) {
public void declareConfiguration(Builder c) {
//c.useInsecureNetClient();
c.useNetClient();
c.enableTelemetry();

}

@Override
public void declareBehavior(FogRuntime runtime) {

HTTPGetBehaviorSingle temp = new HTTPGetBehaviorSingle(runtime);
runtime.addStartupListener(temp);

public void declareBehavior(GreenRuntime runtime) {

int responseId = runtime.addResponseListener(new HTTPResponse()).getId();
runtime.addStartupListener(new HTTPGetBehaviorChained(runtime, responseId));
HTTPSession session = new HTTPSession(
//"javanut.com",80,0);
"127.0.0.1",8088,0);

HTTPGetBehaviorSingle temp = new HTTPGetBehaviorSingle(runtime, session);
runtime.addStartupListener(temp).addSubscription("next");

//HTTPSession session = new HTTPSession("127.0.0.1",8088,0);
//runtime.addResponseListener(new HTTPResponse()).includeHTTPSession(session);
//runtime.addStartupListener(new HTTPGetBehaviorChained(runtime, session));


runtime.addPubSubListener(new ShutdownBehavior(runtime)).addSubscription("shutdown");

}

Expand All @@ -49,26 +56,28 @@ public class HTTPClient implements FogApp
Behavior class:

```java
package com.ociweb.oe.floglight.api;
package com.ociweb.oe.greenlightning.api;

import com.ociweb.gl.api.HTTPSession;
import com.ociweb.gl.api.StartupListener;
import com.ociweb.iot.maker.FogCommandChannel;
import com.ociweb.iot.maker.FogRuntime;
import com.ociweb.gl.api.GreenCommandChannel;
import com.ociweb.gl.api.GreenRuntime;

public class HTTPGetBehaviorChained implements StartupListener {

private FogCommandChannel cmd;
private GreenCommandChannel cmd;
private int responseId;

public HTTPGetBehaviorChained(FogRuntime runtime, int responseId) {
private HTTPSession session;

public HTTPGetBehaviorChained(GreenRuntime runtime, HTTPSession session) {
this.cmd = runtime.newCommandChannel(NET_REQUESTER);
this.responseId = responseId;
this.session = session;
}

@Override
public void startup() {

cmd.httpGet("www.objectcomputing.com", "/", responseId);
cmd.httpGet(session, "/testPageB");

}

Expand All @@ -77,61 +86,98 @@ public class HTTPGetBehaviorChained implements StartupListener {


```java
package com.ociweb.oe.floglight.api;
package com.ociweb.oe.greenlightning.api;

import com.ociweb.gl.api.GreenCommandChannel;
import com.ociweb.gl.api.GreenRuntime;
import com.ociweb.gl.api.HTTPResponseListener;
import com.ociweb.gl.api.HTTPResponseReader;
import com.ociweb.gl.api.HTTPSession;
import com.ociweb.gl.api.Payloadable;
import com.ociweb.gl.api.PubSubListener;
import com.ociweb.gl.api.StartupListener;
import com.ociweb.iot.maker.FogCommandChannel;
import com.ociweb.iot.maker.FogRuntime;
import com.ociweb.pronghorn.network.config.HTTPContentType;
import com.ociweb.pronghorn.pipe.BlobReader;
import com.ociweb.gl.api.TimeListener;
import com.ociweb.pronghorn.pipe.ChannelReader;
import com.ociweb.pronghorn.util.Appendables;

public class HTTPGetBehaviorSingle implements StartupListener, HTTPResponseListener {
public class HTTPGetBehaviorSingle implements StartupListener, HTTPResponseListener, PubSubListener {


private final FogCommandChannel cmd;

public HTTPGetBehaviorSingle(FogRuntime runtime) {
cmd = runtime.newCommandChannel(NET_REQUESTER);
private final GreenCommandChannel cmd;
private HTTPSession session;

public HTTPGetBehaviorSingle(GreenRuntime runtime, HTTPSession session) {
this.session = session;
cmd = runtime.newCommandChannel(NET_REQUESTER | DYNAMIC_MESSAGING);
}


@Override
public void startup() {
cmd.httpGet("www.objectcomputing.com", "/");
cmd.publishTopic("next");
}

long d = 0;
long c = 0;

@Override
public boolean responseHTTP(HTTPResponseReader reader) {

System.out.println(" status:"+reader.statusCode());
System.out.println(" type:"+reader.contentType());
long duration = System.nanoTime()-reqTime;

d+=duration;
c+=1;

if(0==(0xFFF&c)) {//running average
Appendables.appendNearestTimeUnit(System.err, d/c, " latency\n");
}

// System.out.println(" status:"+reader.statusCode());
// System.out.println(" type:"+reader.contentType());

Payloadable payload = new Payloadable() {
@Override
public void read(BlobReader reader) {
System.out.println(reader.readUTFOfLength(reader.available()));
public void read(ChannelReader reader) {
String readUTFOfLength = reader.readUTFOfLength(reader.available());
//System.out.println(readUTFOfLength);
}
};

reader.openPayloadData( payload );

cmd.publishTopic("next");

return true;
}


int countDown = 4000;
long reqTime = 0;

@Override
public boolean message(CharSequence topic, ChannelReader payload) {

if (--countDown<=0) {
cmd.httpGet(session, "/shutdown?key=shutdown");
cmd.publishTopic("shutdown");
}

reqTime = System.nanoTime();
return cmd.httpGet(session, "/testPageB");

}

}
```


```java
package com.ociweb.oe.floglight.api;
package com.ociweb.oe.greenlightning.api;

import com.ociweb.gl.api.HTTPResponseListener;
import com.ociweb.gl.api.HTTPResponseReader;
import com.ociweb.gl.api.Payloadable;
import com.ociweb.pronghorn.network.config.HTTPContentType;
import com.ociweb.pronghorn.pipe.BlobReader;
import com.ociweb.pronghorn.pipe.ChannelReader;

public class HTTPResponse implements HTTPResponseListener {

Expand All @@ -143,7 +189,7 @@ public class HTTPResponse implements HTTPResponseListener {

Payloadable payload = new Payloadable() {
@Override
public void read(BlobReader reader) {
public void read(ChannelReader reader) {
System.out.println(reader.readUTFOfLength(reader.available()));
}
};
Expand All @@ -157,4 +203,3 @@ public class HTTPResponse implements HTTPResponseListener {
```


This class is a simple demonstration of an HTTP Client. HTTP Client will send a request out to an HTTP Server. In this case, the client is sending a request to go to "www.objectcomputing.com".
8 changes: 4 additions & 4 deletions HTTPClient/gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
# Example project:

Demo code:
.include "./src/main/java/com/ociweb/oe/floglight/api/HTTPClient.java"
.include "./src/main/java/com/ociweb/oe/greenlightning/api/HTTPClient.java"
Behavior class:
.include "./src/main/java/com/ociweb/oe/floglight/api/HTTPGetBehaviorChained.java"
.include "./src/main/java/com/ociweb/oe/floglight/api/HTTPGetBehaviorSingle.java"
.include "./src/main/java/com/ociweb/oe/floglight/api/HTTPResponse.java"
.include "./src/main/java/com/ociweb/oe/greenlightning/api/HTTPGetBehaviorChained.java"
.include "./src/main/java/com/ociweb/oe/greenlightning/api/HTTPGetBehaviorSingle.java"
.include "./src/main/java/com/ociweb/oe/greenlightning/api/HTTPResponse.java"

This class is a simple demonstration of an HTTP Client. HTTP Client will send a request out to an HTTP Server. In this case, the client is sending a request to go to "www.objectcomputing.com".
Loading

0 comments on commit 9e50978

Please sign in to comment.