List of usage examples for org.joda.time Duration Duration
public Duration(Object duration)
From source file:com.vaushell.superpipes.nodes.buffer.Slot.java
License:Open Source License
/** * Return the time to wait to be in a slot and not to burst. * * @param date Actual date//from w w w . ja va 2 s . co m * @return the time to wait */ public Duration getSmallestDiff(final DateTime date) { if (areWeInside(date)) { return new Duration(0L); } Duration smallest = null; for (final int dayOfWeek : daysOfWeek) { DateTime next = date.withDayOfWeek(dayOfWeek).withMillisOfDay(minMillisOfDay); if (next.isBefore(date)) { next = next.plusWeeks(1); } final Duration duration = new Duration(date, next); if (smallest == null || duration.isShorterThan(smallest)) { smallest = duration; } } return smallest; }
From source file:com.vaushell.superpipes.nodes.fb.N_FB.java
License:Open Source License
public N_FB() { // Read every 10 minutes super(new Duration(600000L), null); this.client = new FacebookClient(); this.forcedTarget = null; }
From source file:com.vaushell.superpipes.nodes.fb.N_FB_Delete.java
License:Open Source License
@Override protected void loop() throws Exception { // Receive//from ww w . j ava2 s.c o m setMessage(getLastMessageOrWait()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] receive message : " + Message.formatSimple(getMessage())); } // Delete from Facebook if (getMessage().contains("id-facebook")) { final String ID = (String) getMessage().getProperty("id-facebook"); new A_Retry<Void>() { @Override protected Void executeContent() throws IOException, FacebookException { if (client.deletePost(ID)) { return null; } else { throw new IOException("Can't delete post with ID=" + ID); } } }.setRetry(getProperties().getConfigInteger("retry", 10)) .setWaitTime(getProperties().getConfigDuration("wait-time", new Duration(5000L))) .setWaitTimeMultiplier(getProperties().getConfigDouble("wait-time-multiplier", 2.0)) .setJitterRange(getProperties().getConfigInteger("jitter-range", 500)) .setMaxDuration(getProperties().getConfigDuration("max-duration", new Duration(0L))).execute(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] can delete post ID=" + ID); } sendMessage(); } }
From source file:com.vaushell.superpipes.nodes.fb.N_FB_Post.java
License:Open Source License
@Override protected void loop() throws Exception { // Receive/*w ww . ja v a2 s. com*/ setMessage(getLastMessageOrWait()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] receive message : " + Message.formatSimple(getMessage())); } if (!getMessage().contains(Message.KeyIndex.URI)) { throw new IllegalArgumentException("message doesn't have an uri"); } // Send to FB final URI uri = (URI) getMessage().getProperty(Message.KeyIndex.URI); final String uriStr; if (uri == null) { uriStr = null; } else { uriStr = uri.toString(); } final String caption; if (getMessage().contains(Message.KeyIndex.URI_SOURCE)) { caption = ((URI) getMessage().getProperty(Message.KeyIndex.URI_SOURCE)).getHost(); } else { caption = null; } final DateTime date; if (getProperties().getConfigBoolean("backdating", Boolean.FALSE)) { date = (DateTime) getMessage().getProperty(Message.KeyIndex.PUBLISHED_DATE); } else { date = null; } final String ID = new A_Retry<String>() { @Override protected String executeContent() throws FacebookException, IOException { final String title = (String) getMessage().getProperty(Message.KeyIndex.TITLE); final String ID = client.postLink(forcedTarget, (String) getMessage().getProperty(Message.KeyIndex.CONTENT), uriStr, title, caption, (String) getMessage().getProperty(Message.KeyIndex.DESCRIPTION), date); if (ID == null || ID.isEmpty()) { throw new IOException("Cannot post link with title=" + title); } else { return ID; } } }.setRetry(getProperties().getConfigInteger("retry", 10)) .setWaitTime(getProperties().getConfigDuration("wait-time", new Duration(5000L))) .setWaitTimeMultiplier(getProperties().getConfigDouble("wait-time-multiplier", 2.0)) .setJitterRange(getProperties().getConfigInteger("jitter-range", 500)) .setMaxDuration(getProperties().getConfigDuration("max-duration", new Duration(0L))).execute(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] receive ID : " + ID); } getMessage().setProperty("id-facebook", ID); sendMessage(); }
From source file:com.vaushell.superpipes.nodes.fb.N_FB_PostLike.java
License:Open Source License
@Override protected void loop() throws Exception { // Receive// w w w . j a v a 2 s.c om setMessage((Message) getLastMessageOrWait()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] receive message : " + Message.formatSimple(getMessage())); } if (!getMessage().contains("id-facebook")) { throw new IllegalArgumentException("message doesn't have an post id"); } final String ID = (String) getMessage().getProperty("id-facebook"); // Like new A_Retry<Void>() { @Override protected Void executeContent() throws IOException, FacebookException { if (client.likePost(ID)) { return null; } else { throw new IOException("Can't delete post with ID=" + ID); } } }.setRetry(getProperties().getConfigInteger("retry", 10)) .setWaitTime(getProperties().getConfigDuration("wait-time", new Duration(5000L))) .setWaitTimeMultiplier(getProperties().getConfigDouble("wait-time-multiplier", 2.0)) .setJitterRange(getProperties().getConfigInteger("jitter-range", 500)) .setMaxDuration(getProperties().getConfigDuration("max-duration", new Duration(0L))).execute(); sendMessage(); }
From source file:com.vaushell.superpipes.nodes.linkedin.N_LNK.java
License:Open Source License
public N_LNK() { // Read every 10 minutes super(new Duration(600000L), null); this.client = new LinkedInClient(); }
From source file:com.vaushell.superpipes.nodes.linkedin.N_LNK_Post.java
License:Open Source License
@Override protected void loop() throws Exception { // Receive/*from w ww . j ava 2s . c o m*/ setMessage(getLastMessageOrWait()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] receive message : " + Message.formatSimple(getMessage())); } if (!getMessage().contains(Message.KeyIndex.URI)) { throw new IllegalArgumentException("message doesn't have an uri"); } // Send to Twitter final URI uri = (URI) getMessage().getProperty(Message.KeyIndex.URI); final String uriStr; if (uri == null) { uriStr = null; } else { uriStr = uri.toString(); } final String ID = new A_Retry<String>() { @Override protected String executeContent() throws IOException, OAuthException { final String title = (String) getMessage().getProperty(Message.KeyIndex.TITLE); final String ID = client.postLink((String) getMessage().getProperty(Message.KeyIndex.CONTENT), uriStr, title, null); if (ID == null || ID.isEmpty()) { throw new IOException("Cannot post status with title=" + title); } else { return ID; } } }.setRetry(getProperties().getConfigInteger("retry", 10)) .setWaitTime(getProperties().getConfigDuration("wait-time", new Duration(5000L))) .setWaitTimeMultiplier(getProperties().getConfigDouble("wait-time-multiplier", 2.0)) .setJitterRange(getProperties().getConfigInteger("jitter-range", 500)) .setMaxDuration(getProperties().getConfigDuration("max-duration", new Duration(0L))).execute(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] receive ID : " + ID); } getMessage().setProperty("id-linkedin", ID); sendMessage(); }
From source file:com.vaushell.superpipes.nodes.rss.N_RSS.java
License:Open Source License
public N_RSS() { // Read every 10 minutes super(new Duration(600000L), null); }
From source file:com.vaushell.superpipes.nodes.shaarli.N_Shaarli.java
License:Open Source License
public N_Shaarli() { // Read every 10 minutes super(new Duration(600000L), null); this.templates = new ShaarliTemplates(); }
From source file:com.vaushell.superpipes.nodes.shaarli.N_Shaarli_Post.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w w w. ja va2 s . c om*/ protected void loop() throws Exception { // Receive setMessage(getLastMessageOrWait()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] receive message : " + Message.formatSimple(getMessage())); } if (!getMessage().contains(Message.KeyIndex.URI) || !getMessage().contains(Message.KeyIndex.TITLE) || !getMessage().contains(Message.KeyIndex.TAGS)) { throw new IllegalArgumentException("message doesn't have an uri, a title or a set of tags"); } // Send to Shaarli // Log in if (!client.login(getProperties().getConfigString("login"), getProperties().getConfigString("password"))) { throw new IllegalArgumentException("Login error"); } final URI uri = (URI) getMessage().getProperty(Message.KeyIndex.URI); final Tags tags = (Tags) getMessage().getProperty(Message.KeyIndex.TAGS); final String ID = new A_Retry<String>() { @Override protected String executeContent() throws IOException { final String title = (String) getMessage().getProperty(Message.KeyIndex.TITLE); final String ID = client.createLink(uri == null ? null : uri.toString(), title, (String) getMessage().getProperty(Message.KeyIndex.DESCRIPTION), tags == null ? Collections.EMPTY_SET : tags.getAll(), false); if (ID == null || ID.isEmpty()) { throw new IOException("Cannot post link with title=" + title); } else { return ID; } } }.setRetry(getProperties().getConfigInteger("retry", 10)) .setWaitTime(getProperties().getConfigDuration("wait-time", new Duration(5000L))) .setWaitTimeMultiplier(getProperties().getConfigDouble("wait-time-multiplier", 2.0)) .setJitterRange(getProperties().getConfigInteger("jitter-range", 500)) .setMaxDuration(getProperties().getConfigDuration("max-duration", new Duration(0L))).execute(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNodeID() + "] receive ID : " + ID); } getMessage().setProperty("id-shaarli", ID); sendMessage(); }