Skip to content
Permalink
Browse files

Minor Changes

- Starting search engine ping operations (for google and bing) in
separate threads.
- Added toString() method to SitemapEntry for debugging output.
  • Loading branch information...
jfendler committed May 23, 2016
1 parent 834ae0b commit 0de1242f6e813514405825c60fca6bed6c037958
@@ -30,113 +30,120 @@
*/
public class SitemapEntry {

/**
* The date of last modification
*/
private Date lastModified;

/**
* The path to the page
*/
private String pagePath;

/**
* The page priority (0..1)
*/
private double priority;

/**
* The change frequency (use one of the frequency constants from
* {@link Sitemap}.
*/
private int changeFrequency;

/**
* Currently not used.
*/
private String shortName;

/**
* currently not used.
*/
private String shortDescription;

/**
* @param pagePath
* the path of the URL (as in the {@link Router} for non-dynamic
* routes)
*/
public SitemapEntry(String pagePath) {
this(pagePath, new Date(), Sitemap.DAILY, 0.5);
}

/**
* @param pagePath
* the path of the URL (as in the {@link Router} for non-dynamic
* routes)
* @param lastModified
* the last modified Date
* @param changeFrequency
* the expected change frequency for the page (use one of the
* constants from {@link Sitemap#ALWAYS},{@link Sitemap#HOURLY},
* {@link Sitemap#DAILY},{@link Sitemap#WEEKLY},
* {@link Sitemap#MONTHLY},{@link Sitemap#YEARLY}, or
* {@link Sitemap#NEVER},
* @param priority
* the priority of the page (between 0 and 1)
*/
public SitemapEntry(String pagePath, Date lastModified, int changeFrequency, double priority) {
this.pagePath = pagePath;
this.lastModified = lastModified;
this.priority = priority;
}

public Date getLastModified() {
return lastModified;
}

public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}

public String getPagePath() {
return pagePath;
}

public void setPagePath(String pagePath) {
this.pagePath = pagePath;
}

public double getPriority() {
return priority;
}

public void setPriority(double priority) {
this.priority = priority;
}

public int getChangeFrequency() {
return changeFrequency;
}

public void setChangeFrequency(int changeFrequency) {
this.changeFrequency = changeFrequency;
}

public String getShortName() {
return shortName;
}

public void setShortName(String shortName) {
this.shortName = shortName;
}

public String getShortDescription() {
return shortDescription;
}

public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
/**
* The date of last modification
*/
private Date lastModified;

/**
* The path to the page
*/
private String pagePath;

/**
* The page priority (0..1)
*/
private double priority;

/**
* The change frequency (use one of the frequency constants from
* {@link Sitemap}.
*/
private int changeFrequency;

/**
* Currently not used.
*/
private String shortName;

/**
* currently not used.
*/
private String shortDescription;

/**
* @param pagePath
* the path of the URL (as in the {@link Router} for non-dynamic
* routes)
*/
public SitemapEntry(String pagePath) {
this(pagePath, new Date(), Sitemap.DAILY, 0.5);
}

/**
* @param pagePath
* the path of the URL (as in the {@link Router} for non-dynamic
* routes)
* @param lastModified
* the last modified Date
* @param changeFrequency
* the expected change frequency for the page (use one of the
* constants from {@link Sitemap#ALWAYS},{@link Sitemap#HOURLY},
* {@link Sitemap#DAILY},{@link Sitemap#WEEKLY},
* {@link Sitemap#MONTHLY},{@link Sitemap#YEARLY}, or
* {@link Sitemap#NEVER},
* @param priority
* the priority of the page (between 0 and 1)
*/
public SitemapEntry(String pagePath, Date lastModified, int changeFrequency, double priority) {
this.pagePath = pagePath;
this.lastModified = lastModified;
this.priority = priority;
}

public Date getLastModified() {
return lastModified;
}

public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}

public String getPagePath() {
return pagePath;
}

public void setPagePath(String pagePath) {
this.pagePath = pagePath;
}

public double getPriority() {
return priority;
}

public void setPriority(double priority) {
this.priority = priority;
}

public int getChangeFrequency() {
return changeFrequency;
}

public void setChangeFrequency(int changeFrequency) {
this.changeFrequency = changeFrequency;
}

public String getShortName() {
return shortName;
}

public void setShortName(String shortName) {
this.shortName = shortName;
}

public String getShortDescription() {
return shortDescription;
}

public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}

@Override
public String toString() {
return "SitemapEntry [pagePath=" + pagePath + ", lastModified=" + lastModified + ", priority=" + priority
+ ", changeFrequency=" + changeFrequency + ", shortName=" + shortName + ", shortDescription="
+ shortDescription + "]";
}

}
@@ -196,13 +196,17 @@ private String createSitemap(Context context) {
}
final String sitemapUrl = siteUrlPrefix + sitemapRoute;

// pinging search engines will take some time. run this in a new
// thread so that the current request can immediately be served.
// we only want to issue search engine pings in production mode
if (ninjaProperties.isProd()) {
// only ping search engines in PROD mode
Executors.defaultThreadFactory().newThread(new Runnable() {
public void run() {
if (shouldPingGoogle) {

// pinging search engines will take some time. run pinging in
// separate threads so that the current request can immediately
// be served.

// possibly ping Google search engine in separate thread
if (shouldPingGoogle) {
Executors.defaultThreadFactory().newThread(new Runnable() {
public void run() {
try {
generator.pingGoogle(sitemapUrl);
LOG.info("Google search engine has been notified of updated sitemap at '{}'.",
@@ -211,7 +215,13 @@ public void run() {
LOG.warn("Failed to ping Google with updated sitemap.", e);
}
}
if (shouldPingBing) {
}).start();
}

// possibly ping Bing search engine in separate thread
if (shouldPingBing) {
Executors.defaultThreadFactory().newThread(new Runnable() {
public void run() {
try {
generator.pingBing(sitemapUrl);
LOG.info("Bing search engine has been notified of updated sitemap at '{}'.",
@@ -220,8 +230,8 @@ public void run() {
LOG.warn("Failed to ping Google with updated sitemap.", e);
}
}
}
}).start();
}).start();
}
} else {
LOG.info("Not pinging search engines in non-production mode.");
}

0 comments on commit 0de1242

Please sign in to comment.
You can’t perform that action at this time.