use of org.opencastproject.message.broker.api.BaseMessage in project opencast by opencast.
the class MessageSenderImpl method sendObjectMessage.
@Override
public void sendObjectMessage(String destinationId, DestinationType type, Serializable object) {
if (!isConnected()) {
logger.error("Could not send message. No connection to message broker.");
return;
}
try {
synchronized (this) {
Session session = getSession();
// established at least once, but better be safe than sorry.
if (session == null)
return;
// Create a message or use the provided one.
Message message = session.createObjectMessage(new BaseMessage(securityService.getOrganization(), securityService.getUser(), object));
Destination destination;
// Create the destination (Topic or Queue)
if (type.equals(DestinationType.Queue)) {
destination = session.createQueue(destinationId);
} else {
destination = session.createTopic(destinationId);
}
// Tell the producer to send the message
logger.trace("Sent message: " + message.hashCode() + " : " + Thread.currentThread().getName());
// Send the message
getMessageProducer().send(destination, message);
}
} catch (JMSException e) {
logger.error("Had an exception while trying to send a message", e);
}
}
use of org.opencastproject.message.broker.api.BaseMessage in project opencast by opencast.
the class AbstractSearchIndex method recreateService.
/**
* Ask for data to be rebuilt from a service.
*
* @param service
* The {@link IndexRecreateObject.Service} representing the service to start re-sending the data from.
* @throws IndexServiceException
* Thrown if there is a problem re-sending the data from the service.
* @throws InterruptedException
* Thrown if the process of re-sending the data is interupted.
* @throws CancellationException
* Thrown if listening to messages has been canceled.
* @throws ExecutionException
* Thrown if the process of re-sending the data has an error.
*/
private void recreateService(IndexRecreateObject.Service service) throws IndexServiceException, InterruptedException, CancellationException, ExecutionException {
logger.info("Starting to recreate index for service '{}'", service);
messageSender.sendObjectMessage(IndexProducer.RECEIVER_QUEUE + "." + service, MessageSender.DestinationType.Queue, IndexRecreateObject.start(getIndexName(), service));
boolean done = false;
// TODO Add a timeout for services that are not going to respond.
while (!done) {
FutureTask<Serializable> future = messageReceiver.receiveSerializable(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue);
executor.execute(future);
BaseMessage message = (BaseMessage) future.get();
if (message.getObject() instanceof IndexRecreateObject) {
IndexRecreateObject indexRecreateObject = (IndexRecreateObject) message.getObject();
switch(indexRecreateObject.getStatus()) {
case Update:
logger.info("Updating service: '{}' with {}/{} finished, {}% complete.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal(), (int) (indexRecreateObject.getCurrent() * 100 / indexRecreateObject.getTotal()));
if (indexRecreateObject.getCurrent() == indexRecreateObject.getTotal()) {
logger.info("Waiting for service '{}' indexing to complete", indexRecreateObject.getService());
}
break;
case End:
done = true;
logger.info("Finished re-creating data for service '{}'", indexRecreateObject.getService());
break;
case Error:
logger.error("Error updating service '{}' with {}/{} finished.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal());
throw new IndexServiceException(format("Error updating service '%s' with %s/%s finished.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal()));
default:
logger.error("Unable to handle the status '{}' for service '{}'", indexRecreateObject.getStatus(), indexRecreateObject.getService());
throw new IllegalArgumentException(format("Unable to handle the status '%s' for service '%s'", indexRecreateObject.getStatus(), indexRecreateObject.getService()));
}
}
}
}
use of org.opencastproject.message.broker.api.BaseMessage in project opencast by opencast.
the class SchedulerServiceImplTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
wfProperties.put("test", "true");
wfProperties.put("clear", "all");
wfPropertiesUpdated.put("test", "false");
wfPropertiesUpdated.put("skip", "true");
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
schedulerDatabase = new SchedulerServiceDatabaseImpl();
schedulerDatabase.setEntityManagerFactory(mkEntityManagerFactory(SchedulerServiceDatabaseImpl.PERSISTENCE_UNIT));
schedulerDatabase.setSecurityService(securityService);
schedulerDatabase.activate(null);
workspace = new UnitTestWorkspace();
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
final BaseMessage baseMessageMock = EasyMock.createNiceMock(BaseMessage.class);
MessageReceiver messageReceiver = EasyMock.createNiceMock(MessageReceiver.class);
EasyMock.expect(messageReceiver.receiveSerializable(EasyMock.anyString(), EasyMock.anyObject(MessageSender.DestinationType.class))).andStubReturn(new FutureTask<>(new Callable<Serializable>() {
@Override
public Serializable call() throws Exception {
return baseMessageMock;
}
}));
AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
acl = new AccessControlList(new AccessControlEntry("ROLE_ADMIN", "write", true), new AccessControlEntry("ROLE_ADMIN", "read", true), new AccessControlEntry("ROLE_USER", "read", true));
EasyMock.expect(authorizationService.getAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class))).andReturn(Option.some(acl)).anyTimes();
OrganizationDirectoryService orgDirectoryService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
EasyMock.expect(orgDirectoryService.getOrganizations()).andReturn(Arrays.asList((Organization) new DefaultOrganization())).anyTimes();
EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bundleContext.getProperty(EasyMock.anyString())).andReturn("adminuser").anyTimes();
ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
EasyMock.replay(messageSender, baseMessageMock, messageReceiver, authorizationService, securityService, extendedAdapter, episodeAdapter, orgDirectoryService, componentContext, bundleContext);
testConflictHandler = new TestConflictHandler();
schedSvc = new SchedulerServiceImpl();
schedSvc.setAuthorizationService(authorizationService);
schedSvc.setSecurityService(securityService);
schedSvc.setPersistence(schedulerDatabase);
schedSvc.setWorkspace(workspace);
schedSvc.setMessageSender(messageSender);
schedSvc.setMessageReceiver(messageReceiver);
schedSvc.setConflictHandler(testConflictHandler);
schedSvc.addCatalogUIAdapter(episodeAdapter);
schedSvc.addCatalogUIAdapter(extendedAdapter);
schedSvc.setOrgDirectoryService(orgDirectoryService);
schedSvc.activate(componentContext);
}
Aggregations