use of org.bimserver.client.notifications.BinaryMessageListener in project BIMserver by opensourceBIM.
the class TestCheckinAndGeometryDownload method test.
@Test
public void test() throws Exception {
try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
for (int i = 0; i < 100; i++) {
try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
SLongCheckinActionState checkinSync = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> {
});
PackageMetaData packageMetaData = client.getMetaDataManager().getPackageMetaData("ifc2x3tc1");
Query query = new Query(packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addType(packageMetaData.getEClass("IfcProduct"), true);
Tiles tiles = new Tiles();
tiles.add(0);
tiles.setMaximumThreshold(1000);
tiles.setMaxDepth(0);
queryPart.setTiles(tiles);
Include include1 = queryPart.createInclude();
include1.addType(packageMetaData.getEClass("IfcProduct"), true);
include1.addField("geometry");
Include include2 = include1.createInclude();
include2.addType(GeometryPackage.eINSTANCE.getGeometryInfo(), false);
include2.addField("data");
Include include3 = include2.createInclude();
include3.addType(GeometryPackage.eINSTANCE.getGeometryData(), false);
include3.addFieldDirect("indices");
include3.addFieldDirect("normals");
include3.addFieldDirect("normalsQuantized");
include3.addFieldDirect("vertices");
include3.addFieldDirect("verticesQuantized");
include3.addFieldDirect("colorsQuantized");
include3.addFieldDirect("colorPack");
SSerializerPluginConfiguration serializer = client.getPluginInterface().getSerializerByPluginClassName("org.bimserver.serializers.binarygeometry.BinaryGeometryMessagingStreamingSerializerPlugin");
ObjectNode queryJson = new JsonQueryObjectModelConverter(packageMetaData).toJson(query);
queryJson.set("loaderSettings", generateLoaderSettings());
String queryString = queryJson.toString();
Long topicId = client.getServiceInterface().download(Collections.singleton(checkinSync.getRoid()), queryString, serializer.getOid(), false);
ObjectNode downloadMessage = OBJECT_MAPPER.createObjectNode();
downloadMessage.put("action", "download");
downloadMessage.put("token", client.getToken());
downloadMessage.put("topicId", topicId);
CountDownLatch doneCountdown = new CountDownLatch(1);
client.getNotificationsManager().setBinaryMessageListener(topicId, new BinaryMessageListener() {
@Override
public void newData(byte[] bytes, int start, int length) {
ByteBuffer buffer = ByteBuffer.wrap(bytes, start, length).order(ByteOrder.LITTLE_ENDIAN);
// TopicId
buffer.getLong();
int type = buffer.getInt();
if (type == 0) {
} else if (type == 1) {
doneCountdown.countDown();
}
}
});
client.getNotificationsManager().send(downloadMessage);
if (!doneCountdown.await(5, TimeUnit.MINUTES)) {
LOGGER.error("Not finished after 5 minutes!");
}
LOGGER.info("Done");
client.getServiceInterface().cleanupLongAction(topicId);
}
}
}
Thread.sleep(30000);
}
Aggregations