Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
094ed03
Abstracted publishing and added initial HTTP publishing
SamCarlberg Mar 21, 2016
5430b85
HTTP publishing now works
SamCarlberg Mar 22, 2016
bd6b6a9
Merge branch 'master' into feat/http (reverted from commit 66942fbdd1…
SamCarlberg Mar 22, 2016
cbd0974
Changed GripServer to use dependency injection
SamCarlberg Mar 22, 2016
5cc7ecc
Changed HTTP publishing to use the new publishing paradigm.
SamCarlberg Mar 22, 2016
26d7c11
Added support for changing the internal server port
SamCarlberg Mar 22, 2016
2dd88a1
Moved HTTP injection bindings to the correct module
SamCarlberg Mar 22, 2016
0204bb1
Removed debugging println
SamCarlberg Mar 23, 2016
93c5311
Implemented an image source for images POSTed to the HTTP server.
SamCarlberg Mar 23, 2016
fab0bcd
Added tests for GripServer.
SamCarlberg Mar 23, 2016
107a612
Added test for HttpSource, fixed some bugs with GripServer, and remov…
SamCarlberg Mar 24, 2016
3500d26
Fixed UI test compilation error
SamCarlberg Mar 24, 2016
136a50f
Addressed first round of issues in PR
SamCarlberg Mar 24, 2016
45f5edc
Fixed a bug with HttpSource not updating if another image source is r…
SamCarlberg Mar 24, 2016
e993b40
Removed Holder.java and updated Http tests
SamCarlberg Mar 24, 2016
50da5a3
Fixed issue when the server would hang on every other request to a UR…
SamCarlberg Mar 24, 2016
7d05512
Removed println and made GripServerTest not be stupid
SamCarlberg Mar 24, 2016
baa1197
Made GripServerTest not be stupid
SamCarlberg Mar 24, 2016
e966425
Fixed HttpSourceTest, some bugs in GripServer, and various code style…
SamCarlberg Mar 25, 2016
79177cf
Updated and improved test coverage for GripServer
SamCarlberg Mar 25, 2016
cf9b7a3
Improved memory management in HttpSource
SamCarlberg Mar 25, 2016
c4b246d
Improved test converage for HttpSource and GripServer. Fixed some iss…
SamCarlberg Mar 25, 2016
8dc01cd
Added initial support for setting pipelines via HTTP POST operations
SamCarlberg Mar 28, 2016
eeb383a
Changed pipeline upload to upload the contents of a GRIP project rath…
SamCarlberg Mar 29, 2016
2f3ac37
Stopped abusing system properties to define application runtime prope…
SamCarlberg Mar 29, 2016
e3ef3f7
Changed GripException to be a superclass of internal exceptions, fixe…
SamCarlberg Mar 30, 2016
972ac90
Upadted HttpSource imports for new sockets package
SamCarlberg Mar 30, 2016
a2d980f
Removed unused import and added messages to tests
SamCarlberg Apr 6, 2016
576bee9
Fixes not being able to change GripServer socket from the UI
SamCarlberg Apr 18, 2016
6cc33ec
Changed GripServer to return a 500 error on a POST only if an excepti…
SamCarlberg Apr 19, 2016
6245b79
Remove MockPipeline and MockProjectSettings
SamCarlberg Apr 19, 2016
e117fbd
Removes need to specify project file at startup
SamCarlberg Apr 19, 2016
842ed83
Fixes server in headless mode
SamCarlberg Apr 19, 2016
13ede71
Update tests and add null checks
SamCarlberg Apr 19, 2016
9e68636
500 error if no data is received from a POST
SamCarlberg Apr 19, 2016
52d91f6
Pipeline no longer runs during deserialization
SamCarlberg Apr 20, 2016
52a8e26
Fix pipeline not running in UI mode or after loading a project with a…
SamCarlberg Apr 20, 2016
143a762
Change HttpSource to use XStream alias and update javadoc.
SamCarlberg Apr 20, 2016
7061552
Return 503 Service Unavailable when trying to get data when pipeline …
SamCarlberg Apr 21, 2016
a202cdc
Change server to use Jetty.
SamCarlberg Apr 25, 2016
e44a609
Fix tests after migration to Jetty
SamCarlberg Apr 25, 2016
948b49c
Add tests for Jetty handlers
SamCarlberg Apr 25, 2016
7940196
Should fix broken HttpSourceTest on Travis.
SamCarlberg Apr 26, 2016
35bc25e
Change HTTP image source to have configurable path.
SamCarlberg Apr 26, 2016
25f6514
Add tests for HTTP publishing
SamCarlberg Apr 26, 2016
5d38346
Add tests for HttpPipelineSwitcher
SamCarlberg Apr 27, 2016
678c058
Fixes Codacy issues
SamCarlberg Apr 27, 2016
e3231c0
Remove HTTP pipeline switching in GUI mode
SamCarlberg Apr 27, 2016
3de3900
Fix issues found in PR
SamCarlberg Jun 3, 2016
eccb542
Remove unused imports and fields
SamCarlberg Jun 3, 2016
2627052
Remove codacy complaints, automatically register DataHandler with the…
SamCarlberg Jun 6, 2016
ad425f8
Remove unused imports in DataHandler
SamCarlberg Jun 6, 2016
09cfa12
Address issues in PR and remove static state
SamCarlberg Jun 15, 2016
6f798b7
Remove unused imports
SamCarlberg Jun 15, 2016
6da96ff
Comply with checkstyle
SamCarlberg Jun 27, 2016
300d210
Make HTTP data requests block while the pipeline is running
SamCarlberg Jun 27, 2016
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
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ project(":core") {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile group: 'com.google.auto.value', name: 'auto-value', version: '1.1'
compile group: 'com.google.code.gson', name: 'gson', version: '2.6.2'
compile group: 'org.eclipse.jetty', name:'jetty-server', version:'9.3.8.v20160314'
testCompile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
testCompile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.2.2'
testCompile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.2'
// We use the no_aop version of Guice because the aop isn't avaiable in arm java
// http://stackoverflow.com/a/15235190/3708426
// https://github.com/google/guice/wiki/OptionalAOP
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/edu/wpi/grip/core/GripCoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.wpi.grip.core.sockets.OutputSocket;
import edu.wpi.grip.core.sockets.OutputSocketImpl;
import edu.wpi.grip.core.sources.CameraSource;
import edu.wpi.grip.core.sources.HttpSource;
import edu.wpi.grip.core.sources.ImageFileSource;
import edu.wpi.grip.core.sources.MultiImageFileSource;
import edu.wpi.grip.core.util.ExceptionWitness;
Expand Down Expand Up @@ -137,6 +138,9 @@ public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
install(new FactoryModuleBuilder()
.implement(MultiImageFileSource.class, MultiImageFileSource.class)
.build(MultiImageFileSource.Factory.class));
install(new FactoryModuleBuilder()
.implement(HttpSource.class, HttpSource.class)
.build(HttpSource.Factory.class));

install(new FactoryModuleBuilder().build(ExceptionWitness.Factory.class));
}
Expand Down
28 changes: 18 additions & 10 deletions core/src/main/java/edu/wpi/grip/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import edu.wpi.grip.core.events.ExceptionClearedEvent;
import edu.wpi.grip.core.events.ExceptionEvent;
import edu.wpi.grip.core.http.GripServer;
import edu.wpi.grip.core.http.HttpPipelineSwitcher;
import edu.wpi.grip.core.operations.CVOperations;
import edu.wpi.grip.core.operations.Operations;
import edu.wpi.grip.core.operations.network.GripNetworkModule;
Expand All @@ -12,6 +14,7 @@
import com.google.common.eventbus.Subscribe;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.util.Modules;

import java.io.File;
import java.io.IOException;
Expand All @@ -37,30 +40,35 @@ public class Main {
private CVOperations cvOperations;
@Inject
private Logger logger;
@Inject
private GripServer gripServer;
@Inject
private HttpPipelineSwitcher pipelineSwitcher;

@SuppressWarnings({"PMD.SystemPrintln", "JavadocMethod"})
public static void main(String[] args) throws IOException, InterruptedException {
final Injector injector = Guice.createInjector(new GripCoreModule(), new GripNetworkModule(),
new GripSourcesHardwareModule());
final Injector injector = Guice.createInjector(Modules.override(
new GripCoreModule(), new GripSourcesHardwareModule()).with(new GripNetworkModule()));
injector.getInstance(Main.class).start(args);
}

@SuppressWarnings({"PMD.SystemPrintln", "JavadocMethod"})
public void start(String[] args) throws IOException, InterruptedException {
if (args.length != 1) {
System.err.println("Usage: GRIP.jar project.grip");
return;
} else {
String projectPath = null;
if (args.length == 1) {
logger.log(Level.INFO, "Loading file " + args[0]);
projectPath = args[0];
}

operations.addOperations();
cvOperations.addOperations();

final String projectPath = args[0];
gripServer.addHandler(pipelineSwitcher);
gripServer.start();

// Open a project from a .grip file specified on the command line
project.open(new File(projectPath));
if (projectPath != null) {
project.open(new File(projectPath));
}

pipelineRunner.startAsync();

Expand Down Expand Up @@ -88,4 +96,4 @@ public final void onExceptionClearedEvent(ExceptionClearedEvent event) {
+ "Event");
}

}
}
7 changes: 7 additions & 0 deletions core/src/main/java/edu/wpi/grip/core/PipelineRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import edu.wpi.grip.core.events.RenderEvent;
import edu.wpi.grip.core.events.RunPipelineEvent;
import edu.wpi.grip.core.events.RunStartedEvent;
import edu.wpi.grip.core.events.RunStoppedEvent;
import edu.wpi.grip.core.events.StopPipelineEvent;
import edu.wpi.grip.core.util.SinglePermitSemaphore;
import edu.wpi.grip.core.util.service.AutoRestartingService;
Expand All @@ -28,6 +30,8 @@
import javax.annotation.Nullable;
import javax.inject.Inject;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Runs the pipeline in a separate thread. The runner listens for {@link RunPipelineEvent
* RunPipelineEvents} and releases the pipeline thread to update the sources and run the steps.
Expand Down Expand Up @@ -68,6 +72,7 @@ protected void runOneIteration() throws InterruptedException {
}

pipelineFlag.acquire();
eventBus.post(new RunStartedEvent());

if (!super.isRunning()) {
return;
Expand All @@ -77,6 +82,7 @@ protected void runOneIteration() throws InterruptedException {
if (super.isRunning()) {
eventBus.post(new RenderEvent());
}
eventBus.post(new RunStoppedEvent());
}

@Override
Expand Down Expand Up @@ -196,6 +202,7 @@ private void runPipeline(Supplier<Boolean> isRunning) {
@Subscribe
@AllowConcurrentEvents
public void onRunPipeline(RunPipelineEvent event) {
checkNotNull(event);
if (event.pipelineShouldRun()) {
pipelineFlag.release();
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/edu/wpi/grip/core/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.wpi.grip.core.sockets.OutputSocket;
import edu.wpi.grip.core.sources.CameraSource;
import edu.wpi.grip.core.sources.HttpSource;
import edu.wpi.grip.core.sources.ImageFileSource;
import edu.wpi.grip.core.sources.MultiImageFileSource;
import edu.wpi.grip.core.util.ExceptionWitness;
Expand Down Expand Up @@ -108,6 +109,8 @@ public static class SourceFactoryImpl implements SourceFactory {
ImageFileSource.Factory imageFactory;
@Inject
MultiImageFileSource.Factory multiImageFactory;
@Inject
HttpSource.Factory httpFactory;

@Override
public Source create(Class<?> type, Properties properties) throws IOException {
Expand All @@ -117,6 +120,8 @@ public Source create(Class<?> type, Properties properties) throws IOException {
return imageFactory.create(properties);
} else if (type.isAssignableFrom(MultiImageFileSource.class)) {
return multiImageFactory.create(properties);
} else if (type.isAssignableFrom(HttpSource.class)) {
return httpFactory.create(properties);
} else {
throw new IllegalArgumentException(type + " was not a valid type");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package edu.wpi.grip.core.events;

/**
* An event fired when the pipeline starts running. This is guaranteed to be followed by a
* corresponding {@link RunStoppedEvent}.
*/
public class RunStartedEvent {
}
11 changes: 11 additions & 0 deletions core/src/main/java/edu/wpi/grip/core/events/RunStoppedEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package edu.wpi.grip.core.events;

/**
* An event fired when the pipeline stops running. This is guaranteed to follow a corresponding
* {@link RunStartedEvent}.
*
* <p>This is different from {@link RenderEvent} in that it will <i>always</i> be fired when the
* pipeline runs.
*/
public class RunStoppedEvent {
}
19 changes: 19 additions & 0 deletions core/src/main/java/edu/wpi/grip/core/exception/GripException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

package edu.wpi.grip.core.exception;

/**
* An exception thrown when something goes wrong with an internal GRIP
* operation. This class is {@code abstract} to encourage making subclasses
* for specific cases.
*/
public abstract class GripException extends RuntimeException {

public GripException(String message) {
super(message);
}

public GripException(String message, Throwable cause) {
super(message, cause);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package edu.wpi.grip.core.exception;

/**
* An exception thrown when something goes wrong in the
* {@link edu.wpi.grip.core.http.GripServer GripServer}.
*/
public class GripServerException extends GripException {

public GripServerException(String message) {
super(message);
}

public GripServerException(String message, Throwable cause) {
super(message, cause);
}
}
58 changes: 58 additions & 0 deletions core/src/main/java/edu/wpi/grip/core/http/ContextStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package edu.wpi.grip.core.http;

import com.google.inject.Singleton;

import java.util.HashSet;
import java.util.Set;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Keeps a record of contexts claimed by HTTP request handlers.
*/
@Singleton
public class ContextStore {

private final Set<String> store = new HashSet<>();

/**
* Records the given context.
*
* @param context the context to record. This cannot be null.
* @throws IllegalArgumentException if the given context has already been claimed
*/
public void record(@Nonnull String context) throws IllegalArgumentException {
checkNotNull(context);
if (!store.add(context)) {
throw new IllegalArgumentException("Context is already claimed: " + context);
}
}

/**
* Erases the given context from this store, if it's present. If {@code context} is {@code null},
* this will do nothing and return {@code false}.
*
* @param context the context to erase
* @return true if the context was erased, false if it wasn't erased
* or if it wasn't present to begin with.
*/
public boolean erase(@Nullable String context) {
return store.remove(context);
}

/**
* Checks if the given context has been recorded in this store.
* If {@code context} is {@code null}, this will return {@code false}.
*
* @param context the context to check
* @return true if the given context has been recorded in this store
*/
public boolean contains(@Nullable String context) {
return store.contains(context);
}


}
Loading