Commit fd51c4fe by Svetoslav Videnov

updated scenario 1 to startup like scenario 2

parent bfbd9b9b
......@@ -2,6 +2,8 @@ dependencies {
compile project(':programming-framework-runtime')
compile project(':programming-framework-pm')
compile project(':programming-framework-smartcom')
compile project(":programming-framework-scenario2")
compile 'at.ac.tuwien.dsg:smartcom-impl:1.0-SNAPSHOT'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile ('at.ac.tuwien.dsg:googlePeer:0.1-SNAPSHOT')
}
......@@ -5,6 +5,8 @@
*/
package eu.smartsocietyproject.scenario1;
import at.ac.tuwien.dsg.GooglePeerFactory;
import at.ac.tuwien.dsg.SoftwarePeer;
import at.ac.tuwien.dsg.smartcom.adapters.RESTInputAdapter;
import at.ac.tuwien.dsg.smartcom.callback.NotificationCallback;
import at.ac.tuwien.dsg.smartcom.exception.CommunicationException;
......@@ -25,6 +27,9 @@ import eu.smartsocietyproject.pf.helper.InternalPeerManager;
import eu.smartsocietyproject.pf.helper.PeerIntermediary;
import eu.smartsocietyproject.runtime.Runtime;
import eu.smartsocietyproject.scenario1.helper.RQATaskDefinition;
import eu.smartsocietyproject.scenario2.helper.GreenMail.RunMailServer;
import eu.smartsocietyproject.scenario2.helper.GreenMailOutputAdapter;
import eu.smartsocietyproject.scenario2.helper.PeerLoader;
import eu.smartsocietyproject.smartcom.PeerChannelAddressAdapter;
import eu.smartsocietyproject.smartcom.SmartComServiceImpl;
import java.io.IOException;
......@@ -38,13 +43,24 @@ import java.util.Properties;
public class Scenario1 implements NotificationCallback {
private static Runtime runtime;
private static final boolean DEMO = true;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException, CommunicationException {
if (DEMO) {
RunMailServer.start();
}
CollectiveKindRegistry kindRegistry = CollectiveKindRegistry
.builder().register(CollectiveKind.EMPTY).build();
SoftwarePeer googlePeer = GooglePeerFactory.startPeer(Thread
.currentThread()
.getContextClassLoader()
.getResourceAsStream("GooglePeer.properties"));
MongoRunner runner = MongoRunner.withPort(6666);
PeerManagerMongoProxy.Factory pmFactory
......@@ -58,8 +74,13 @@ public class Scenario1 implements NotificationCallback {
new SmartComServiceImpl.Factory(client));
SmartComServiceImpl smartCom = (SmartComServiceImpl) context.getSmartCom();
InternalPeerManager pm = (InternalPeerManager) context.getPeerManager();
if (DEMO) {
smartCom.getCommunication()
.removeOutputAdapter(Identifier.adapter("Email"));
smartCom.getCommunication()
.registerOutputAdapter(GreenMailOutputAdapter.class);
}
//todo-sv: if the platform is responsible for setting up and handling
//smartcom correctly how does the platform know what input adapters
......@@ -69,53 +90,8 @@ public class Scenario1 implements NotificationCallback {
//but this adapter itself does not have a peer to which it belongs
//how can we make the smartcom service know on whoch channels
//to expect responses?
pm.persistPeer(PeerIntermediary
.builder("google", "SWPeerForSearch")
.addDeliveryAddress(PeerChannelAddressAdapter
.convert(new PeerChannelAddress(
Identifier.peer("google"),
Identifier.channelType("REST"),
Arrays.asList("http://localhost:8000/"))
)
)
.addAttribute("restaurantQA", AttributeType.from("true"))
.build());
pm.persistPeer(PeerIntermediary
.builder("sveti", "HumanExpert")
.addDeliveryAddress(PeerChannelAddressAdapter
.convert(new PeerChannelAddress(
Identifier.peer("sveti"),
Identifier.channelType("Email"),
Arrays.asList("svetoslav.videnov@infosys.tuwien.ac.at"))
)
)
.addAttribute("restaurantQA", AttributeType.from("true"))
.build());
pm.persistPeer(PeerIntermediary
.builder("sveto", "HumanExpert")
.addDeliveryAddress(PeerChannelAddressAdapter
.convert(new PeerChannelAddress(
Identifier.peer("sveto"),
Identifier.channelType("Email"),
Arrays.asList("videnov.svetoslav@gmail.com"))
)
)
.addAttribute("restaurantQA", AttributeType.from("true"))
.build());
pm.persistPeer(PeerIntermediary
.builder("vauvenal5", "HumanExpert")
.addDeliveryAddress(PeerChannelAddressAdapter
.convert(new PeerChannelAddress(
Identifier.peer("vauvenal5"),
Identifier.channelType("Email"),
Arrays.asList("vauvenal5@gmail.com"))
)
)
.addAttribute("restaurantQA", AttributeType.from("true"))
.build());
PeerLoader.laodPeers(context);
smartCom.registerNotificationCallback(new Scenario1());
Properties props = new Properties();
......
......@@ -15,9 +15,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
hostOutgoing=smtp.gmail.com
portOutgoing=465
hostIncoming=pop.gmail.com
portIncoming=995
username=smartcom.ssp@gmail.com
password=
\ No newline at end of file
hostOutgoing=localhost
portOutgoing=3465
hostIncoming=localhost
portIncoming=3110
username=smartcom.ssp@localhost
password=smartcom.ssp
\ No newline at end of file
# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
google.search.api_key=
google.search.id=
smartsociety.ask.message_url=http://localhost:9696/searchResult
smartsociety.peer_id=google
\ No newline at end of file
[
{
"name": "google",
"channelType": "REST",
"channel": "http://localhost:8000/",
"role": "SWPeerForSearch"
},
{
"name": "peerOrch",
"channelType": "Email",
"channel": "peerOrch@localhost",
"role": "HumanExpert"
},
{
"name": "peer1",
"channelType": "Email",
"channel": "peer1@localhost",
"role": "HumanExpert"
},
{
"name": "peer2",
"channelType": "Email",
"channel": "peer2@localhost",
"role": "HumanExpert"
}
]
......@@ -29,6 +29,7 @@ import eu.smartsocietyproject.runtime.Runtime;
import eu.smartsocietyproject.scenario2.helper.GreenMailOutputAdapter;
import eu.smartsocietyproject.scenario2.helper.GreenMail.RunMailServer;
import eu.smartsocietyproject.scenario2.helper.JsonPeer;
import eu.smartsocietyproject.scenario2.helper.PeerLoader;
import eu.smartsocietyproject.scenario2.helper.RQATaskDefinition;
import eu.smartsocietyproject.smartcom.PeerChannelAddressAdapter;
import eu.smartsocietyproject.smartcom.SmartComServiceImpl;
......@@ -45,7 +46,6 @@ public class Scenario2 implements NotificationCallback {
private static Runtime runtime;
private static final boolean variantA = true;
private static final ObjectMapper mapper = new ObjectMapper();
private static final boolean DEMO = true;
/**
......@@ -84,27 +84,7 @@ public class Scenario2 implements NotificationCallback {
.registerOutputAdapter(GreenMailOutputAdapter.class);
}
InternalPeerManager pm = (InternalPeerManager) context.getPeerManager();
List<JsonPeer> peers = mapper.readValue(Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("Peers.json"),
mapper.getTypeFactory()
.constructCollectionType(List.class, JsonPeer.class));
peers.stream().forEach(peer -> {
pm.persistPeer(PeerIntermediary
.builder(peer.getName(), peer.getRole())
.addDeliveryAddress(PeerChannelAddressAdapter
.convert(new PeerChannelAddress(
Identifier.peer(peer.getName()),
Identifier.channelType(peer.getChannelType()),
Arrays.asList(peer.getChannel()))
)
)
.addAttribute("restaurantQA", AttributeType.from("true"))
.build());
});
PeerLoader.laodPeers(context);
smartCom.registerNotificationCallback(new Scenario2());
Properties props = new Properties();
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package eu.smartsocietyproject.scenario2.helper;
import at.ac.tuwien.dsg.smartcom.model.Identifier;
import at.ac.tuwien.dsg.smartcom.model.PeerChannelAddress;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.smartsocietyproject.peermanager.PeerManager;
import eu.smartsocietyproject.pf.AttributeType;
import eu.smartsocietyproject.pf.SmartSocietyApplicationContext;
import eu.smartsocietyproject.pf.helper.InternalPeerManager;
import eu.smartsocietyproject.pf.helper.PeerIntermediary;
import eu.smartsocietyproject.smartcom.PeerChannelAddressAdapter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
*
* @author Svetoslav Videnov <s.videnov@dsg.tuwien.ac.at>
*/
public class PeerLoader {
private static final ObjectMapper mapper = new ObjectMapper();
public static void laodPeers(SmartSocietyApplicationContext context) throws IOException {
InternalPeerManager pm = (InternalPeerManager) context.getPeerManager();
List<JsonPeer> peers = mapper.readValue(Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("Peers.json"),
mapper.getTypeFactory()
.constructCollectionType(List.class, JsonPeer.class));
peers.stream().forEach(peer -> {
pm.persistPeer(PeerIntermediary
.builder(peer.getName(), peer.getRole())
.addDeliveryAddress(PeerChannelAddressAdapter
.convert(new PeerChannelAddress(
Identifier.peer(peer.getName()),
Identifier.channelType(peer.getChannelType()),
Arrays.asList(peer.getChannel()))
)
)
.addAttribute("restaurantQA", AttributeType.from("true"))
.build());
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment