Skip to content

Commit

Permalink
use subscription for queries in status agent and fix resource publica…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
ap-actoron committed Feb 22, 2021
1 parent 9456c0f commit d8cc0a8
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import jadex.bridge.service.IServiceIdentifier;
import jadex.bridge.service.annotation.Service;
import jadex.bridge.service.search.QueryEvent;
import jadex.bridge.service.search.ServiceEvent;
import jadex.bridge.service.search.ServiceQuery;
import jadex.bridge.service.types.transport.PlatformData;
Expand Down Expand Up @@ -34,6 +35,7 @@ public interface IStatusService
// No intermediate for easier REST?
// TODO: subscription in registry to get notified about new queries? -> please no polling!
public IFuture<Collection<ServiceQuery<?>>> getQueries(String... scope);
public ISubscriptionIntermediateFuture<QueryEvent> subscribeToQueries(String... scope);

// /**
// * Get provided services of a given (set of) scope(s) or no scope for all services.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import jadex.bridge.service.ServiceScope;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.bridge.service.search.IServiceRegistry;
import jadex.bridge.service.search.QueryEvent;
import jadex.bridge.service.search.ServiceEvent;
import jadex.bridge.service.search.ServiceQuery;
import jadex.bridge.service.search.ServiceQueryInfo;
Expand All @@ -38,6 +39,7 @@
import jadex.commons.future.ISubscriptionIntermediateFuture;
import jadex.commons.future.IntermediateDelegationResultListener;
import jadex.commons.future.IntermediateFuture;
import jadex.commons.future.SubscriptionIntermediateDelegationFuture;
import jadex.commons.future.SubscriptionIntermediateFuture;
import jadex.commons.future.TerminationCommand;
import jadex.micro.annotation.Agent;
Expand Down Expand Up @@ -75,10 +77,12 @@ protected IFuture<Void> publish(IWebPublishService wps)
IFuture<Void> ret = (IFuture<Void>)
wps.publishService(sid, new PublishInfo("[http://localhost:"+port+"/]status", IPublishService.PUBLISH_RS, null))
.then(v ->
wps.publishResources("[http://localhost:"+port+"/]", "META-INF/legacystatuswebgui"));
wps.publishResources("[http://localhost:"+port+"/]", "META-INF/legacystatuswebgui")
.then(w ->
wps.publishResources("[http://localhost:"+port+"/]", "META-INF/resources")));
return ret;
}

@Override
public IIntermediateFuture<PlatformData> getConnectedPlatforms()
{
Expand Down Expand Up @@ -120,6 +124,32 @@ public void resultAvailable(Void result)
});
return ret;
}

/**
* Get registered queries of a given (set of) scope(s) or no scope for all queries.
* @return A list of queries.
*/
public ISubscriptionIntermediateFuture<QueryEvent> subscribeToQueries(String... scope)
{
Set<String> scopes = scope==null ? null: new HashSet<String>(Arrays.asList(scope));
ISubscriptionIntermediateFuture<QueryEvent> ret = new SubscriptionIntermediateDelegationFuture<QueryEvent>(ServiceRegistry.getRegistry(agent.getId()).subscribeToQueries())
{
@Override
public boolean doAddIntermediateResult(QueryEvent event, boolean undone)
{
if(scopes==null || scopes.contains(event.getQuery().getScope().name().toLowerCase()))
{
return super.doAddIntermediateResult(event, undone);
}
else
{
System.out.println("query ignored in status agent: "+event);
}
return false;
}
};
return ret;
}

@Override
public ISubscriptionIntermediateFuture<PlatformData> subscribeToConnections()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ app.controller('Services', [ '$scope', '$http',
});
}
]);
app.controller('Queries', [ '$scope', '$http',
function($scope, $http) {
getIntermediate($http, 'status/subscribeToQueries',
function(response)
{
updateQuery($scope, response.data);
},
function(response)
{
$scope.superpeerDown = true;
});
}
]);
app.controller('Queries', [ '$scope', '$http',
function($scope, $http) {
$http.get('status/getQueries',
Expand Down Expand Up @@ -95,4 +108,34 @@ function updateService($scope, event)
$scope.services.push(event.service);
}
}

function updateQuery($scope, event)
{
var found = false;
$scope.queries = $scope.queries===undefined ? [] : $scope.queries;

// alert("Query: "+JSON.stringify(event));
for(var i=0; i<$scope.queries.length; i++)
{
found = $scope.queries[i].id==event.query.id;
if(found)
{
// 0: added, 1: removed, 2: changed
if(event.type==1) // removed
{
$scope.queries.splice(i,1);
}
else // added / changed
{
$scope.queries[i] = event.query;
}
break;
}
}

if(!found)
{
$scope.queries.push(event.query);
}
}
//]]>
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testStatusPage() throws IOException
assertContainsField(service, "unrestricted");

// Check that queries can be retrieved.
String query = getUrlContent(new URL("http://localhost:"+port+"/status/getQueries"));
String query = getUrlContent(new URL("http://localhost:"+port+"/status/subscribeToQueries"));
System.out.println("query: "+query);
assertContainsField(query, "serviceType");
assertContainsField(query, "owner");
Expand Down

0 comments on commit d8cc0a8

Please sign in to comment.