You are here

Invalidate targeted announcement cache?

Submitted by jsumners on Thu, 02/02/2012 - 09:26

Does anyone know how to force an invalidation of the targeted announcement cache without restarting Luminis? I know how to add a new announcement by inserting the proper information into the database, but the announcement doesn't get "sent" until the announcement cache is rebuilt (i.e. Luminis is restarted).

Luminis Version:

As you've noticed creating the TA entry in the database manually doesn't create a message instance automatically. The best way to handle creating TA's outside of the TA manager in the portal is through the TA API. You may even be able to leverage the TA API to send the messages you've already created manually but I'm not completely sure since my testing of it was limited to sending new messages and retrieving messages.

-Tom

The problem with using the SOAP API, other than it being gawd awful SOAP, is that it requires a user with permissions to the target channel. I'm working on adding something to our SSB for advisers so that they can send personal announcements to their advisees. I want 1) avoid dealing with SOAP in pl/sql and 2) avoid using a generic posting account.

I'm going to try running with out a TA cache for now and see how it affects performance. I have a feeling I won't need the cache at all. But I would still like to know how to invalidate the TA cache if anyone else can get it figured out.

Ah yes with a more complete picture of what you're working on the TA API wouldn't really be helpful. After playing with it and evaluating its usefulness I decided not to use it as well.

I'd be interested to hear if disabling the cache has an impact on performance and if there is a way to refresh the cache.

-Tom

I could not figure out how to disable the targeted announcement cache. None of the configman settings that seemed appropriated worked. But I did figure out how to poke the cache to make it re-generate :)

1) Create directory under your "webservice" app on your resource tier and create the following index.jsp:

<%@page language="java" contentType="application/json; charset=utf-8" pageEncoding="utf-8" %>
<%@page import="com.sct.pipeline.configuration.Configuration" %>
<%@page import="com.pipeline.abm.object.TargetedAnnouncement" %>
<%@page import="com.pipeline.abm.TMSJanitor" %>
<%@page import="org.json.*" %>

<%
JSONObject outJSON = new JSONObject();
String strTaid = request.getParameter("taid");
int taid = -1;

// We require a message ID to deliver
if (strTaid == null) {
outJSON.put("errorId", 0);
outJSON.put("errorMsg", "Missing 'taid' parameter.");
out.print(outJSON.toString());
return;
}

// The message ID needs to be a number
try {
taid = Integer.parseInt(strTaid);
} catch (NumberFormatException nfe) {
outJSON.put("errorId", 1);
outJSON.put("errorMsg", nfe.toString());
out.print(outJSON.toString());
return;
}

// We need an instance of TMSJanitor before we can do anything
TMSJanitor tj = TMSJanitor.getInstance();
if (!tj.isEnabled()) {
outJSON.put("errorId", 2);
outJSON.put("errorMsg", "Cannot get an instance of TMSJanitor.");
out.print(outJSON.toString());
return;
}

// Get our announcement from the database if it exists
TargetedAnnouncement ta = (new TargetedAnnouncement()).getTAById(taid);
if (ta == null) {
outJSON.put("errorId", 3);
outJSON.put("errorMsg", "Could not find the requested announcement.");
out.print(outJSON.toString());
return;
}

// Finally, we tell the janitor to "send" this announcement.
// Really, we're just poking TargetedAnnouncement.ensureCacheIsValid() with
// a really long stick because it is a private method (for who knows why).
tj.addDeliveryToQueue(ta);

outJSON.put("success", true);
out.print(outJSON.toString());
%>

2) Create a Luminis user that has privileges (a "role" in my case) such that he can post announcements to some sort of targeted announcement channel (most likely this user should have access to all channels that he will update, but I haven't tested that).

3) Write your code that inserts announcements directly into the ta_message and ta_x_user tables (setting whatever parameters you like to whatever values are appropriate).

4) Write some code that hits the above JSP with the taid you just created.

This forces Luminis to invalidate its targeted announcement cache and re-build it. You can even sit on a list of targeted announcements in the portal, send an announcement, hit the new web service, and then click the "Refresh List" button in the portal to see your announcement immediately delivered without having to logout and re-login.

One thing to note: your database inserts/updates should be committed before you hit the web service. Also, you can use PL/JSON to parse the text returned from the web service.