• No results found

4.4 New Transient Information Publishing Pipeline

4.4.3 Twitter Publishing Task

Social website platforms have become very popular platforms for people acquiring information; many people visit social website platforms many times each day, so it is worthwhile to publish new transient information on social website platforms. Thus, we implement a Twitter publishing task in our publisher application; this publishing task will post a tweet message that describes new transient information on the MOA twitter account, and all MOA followers will receive the new transient information from either the Twitter website or the Twitter mobile application immediately. In fact, Twitter works in quite a different way from email. When we send a tweet message, the tweet message will reach the Twitter server as the first stage, and all the remaining operations (find user account, update new tweet on corresponding user account, list new tweet on follower account, etc.) are done in the Twitter server, rather than forwarding the tweet message to some other servers as with email. Furthermore, when a new tweet message has been updated to the MOA twitter account, the Twitter server will respond by sending an error message to the Twitter publishing task when the tweet message fails to update to the MOA twitter account, so we will know whether or not followers can see the new transient information.

The first step in implementing the Twitter publishing task is registering the Twitter developer account to obtain Twitter Rest [146] API access keys, which are the

OAuthConsumerKey, OAuthConsumerSecret, OAuthAccessToken and

OAuthAccessTokenSecret. These four keys are very important and are unique for

each developer account. Without these four keys, we are not able to post “tweet” messages on Twitter from our publisher application.

120

After acquiring the Twitter API access keys, the second step is designing what type of transient information should be presented in the tweet message. In fact, the new transient information presented in the tweet message cannot be same as in the email message, because Twitter has a character limit (140 characters) for each tweet message, so the tweet message should describe the new transient information in a much briefer way than the email message. After discussion, we decided to present the external ID of the new transient, sky coordination (RA and Dec), initial nature and web URL of the new transient profile in the tweet message, because these pieces of information can provide a basic picture of the new transient to end users. If the end users are interested in the new transient, they can access the full transient profile through clicking on the web URL in the tweet message.

Note that we cannot present the full web URL of the transient profile in the tweet message, because this will cause the message to go over the character limit. Thus, we need to transform the full web URL to a short URL [147] format. The web URL shortened operation can be done through using the bit.ly service, which is a URL shortening service; it provides the ability to transform a web URL from the full URL format to a short URL format, and it is the default URL shortening service used by Twitter. Example codes for transfer full URL to short URL via using bit.ly service are as shown below:

1 HttpClient httpclient = new HttpClient();

2 //bitly service API address

3 HttpMethod method = new GetMethod("http://api.bit.ly/shorten");

4 method.setQueryString(new NameValuePair[] {

5 new NameValuePair("version", "2.0.1"),

6 new NameValuePair("longUrl",

7 eventWebAddress),

8 new NameValuePair("login","user account"),

9 new NameValuePair("apiKey",

10 "API access key"),

11 //bit service supports xml and

12 //json as return format

13 new NameValuePair("format", "xml")}

14 );

15 httpclient.executeMethod(method);

Code example 7: using HttpClient to communicate bit.ly REST API in order to transform full web URL to short URL format.

121

To using the bit.ly service, we need to register a bit.ly development account in order to obtain a service API access key, and then we can access the URL shortening API by using the http communication feature provided by the programming language (in our example this is HttpClient).

After the above codes have been executed, the bit.ly service will return an XML string as the response result, and we can retrieve the short URL address from the XML string through utilising XML DOM (Document Object Model). The short URL retrieval process can be programmed as code example 8:

1 String responseXML = method.getResponseBodyAsString();

2 if (responseXML != null)

3 {

4 DocumentBuilderFactory dbf =

5 DocumentBuilderFactory.newInstance();

6 DocumentBuilder db = dbf.newDocumentBuilder();

7 StringReader st = new StringReader(responseXML);

8 Document d = db.parse(new InputSource(st));

9 NodeList nl = d.getElementsByTagName("shortUrl");

10 if (nl != null) 11 { 12 Node n = nl.item(0); 13 shortURL = n.getTextContent(); 14 } 15 }

Code example 8: Get the response from bit.ly and extracts the shortened URL format from the XML document.

Once the short URL has been retrieved, all of the necessary information for the tweet message is ready, and the last pieces of code for this publishing task are posting the tweet message on the MOA Twitter account.

To post a tweet message on Twitter, the Twitter library needs to be downloaded and implemented in the publisher application. Twitter provides its library in many programming languages for developers, but we only use the Java version of the Twitter library in our example, because our publisher application is implemented based on Java.

122

Once the Twitter library has been successfully included in the publisher application, we are able to post a tweet message on Twitter through the use of the following codes:

1 ConfigurationBuilder cb = new ConfigurationBuilder();

2 //Twitter API access keys obtain in the step 1

3 cb.setOAuthConsumerKey("consumerKey ");

4 cb.setOAuthConsumerSecret("ConsumerSecret");

5 cb.setOAuthAccessToken("AccessToken");

6 cb.setOAuthAccessTokenSecret("TokenSecret")

7 //Create Twitter factory instance, the Twitter factory

8 //is class provided by the Twitter library

9 TwitterFactory factor = new TwitterFactory(cb.build());

10 Twitter twitter = factor.getInstance();

11 //Posting twitee message on Twitter

12 twitter.updateStatus(msg);

Code example 9: Posing new tweet about new transient information on MOA’s Twitter account. The variable “msg” in the updateStatus method is the actual message that needs to be posted on Twitter; it can be any string value.

If above codes are successfully executed, the new tweet message will be sent to the Twitter server after the updateStatus function is completed, and the time taken for the new tweet message displayed on the twitter account is fully dependent on the network traffic of both the sender side and the Twitter server side.

Performance limitation of Twitter Publishing Task

The performance limitation of the Twitter publishing task is similar to the email publishing task; if both publisher application side and Twitter server side has a good network connection environment, the new transient information will be updated on MOA’s twitter account immediately after the Twitter publishing task is completed.

However, if the Twitter publishing task has the same network performance issue as the email publishing task, this network issue will lead to there being a delay in the updating of new transient information on MOA’s twitter account. In fact, a network latency problem exists in all of the distribution systems and there is no way to avoid it.

In fact, email and Twitter present no problems for event rates in the current transient detection projects, but these two approaches are clearly unsuitable for LSST. However, LSST could post those very important transient discoveries on Twitter, or send email

123 notifications to all interested recipients.