| Appendix D: Singleton Session EJB: RSS Cache Example in Java

Draw QR Code in Java | Appendix D: Singleton Session EJB: RSS Cache Example

506 | Appendix D: Singleton Session EJB: RSS Cache Example
Make Denso QR Bar Code In Java
Using Barcode creator for Java Control to generate, create QR Code JIS X 0510 image in Java applications.
www.OnBarcode.com
Scanning Quick Response Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
}
PDF 417 Printer In Java
Using Barcode drawer for Java Control to generate, create PDF417 image in Java applications.
www.OnBarcode.com
Barcode Encoder In Java
Using Barcode generator for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
}
Painting Barcode In Java
Using Barcode generation for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
ANSI/AIM Code 39 Generation In Java
Using Barcode printer for Java Control to generate, create USS Code 39 image in Java applications.
www.OnBarcode.com
} catch (final MalformedURLException e) { throw new RuntimeException("Error in copying URL", e); }
Draw DataMatrix In Java
Using Barcode maker for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
www.OnBarcode.com
UPC Shipping Container Symbol ITF-14 Printer In Java
Using Barcode creator for Java Control to generate, create ITF-14 image in Java applications.
www.OnBarcode.com
// Copy return new URL(url.toExternalForm());
QR Code Printer In Objective-C
Using Barcode printer for iPad Control to generate, create QR Code JIS X 0510 image in iPad applications.
www.OnBarcode.com
Paint Quick Response Code In Java
Using Barcode maker for Java Control to generate, create QR Code JIS X 0510 image in Java applications.
www.OnBarcode.com
RomeRssEntry.java
Read UPC A In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Generating PDF-417 2d Barcode In .NET
Using Barcode printer for Visual Studio .NET Control to generate, create PDF 417 image in Visual Studio .NET applications.
www.OnBarcode.com
package org.jboss.ejb3.examples.ch07.rsscache.impl.rome; import java.net.MalformedURLException; import java.net.URL; import org.jboss.ejb3.examples.ch07.rsscache.spi.RssEntry; import com.sun.syndication.feed.synd.SyndContent; import com.sun.syndication.feed.synd.SyndEntry; /** * The java.net Rome implementation of an RSS Entry * * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a> */ public class RomeRssEntry implements RssEntry { //--------------------------------------------------------------------------|| // Instance Members --------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * The author of the entry */ private String author; /** * The short description of the entry */ private String description; /** * The title of the entry */ private String title; /** * The link to the entry */ private URL url;
Read EAN128 In C#
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
EAN / UCC - 13 Generator In None
Using Barcode creator for Word Control to generate, create UCC-128 image in Office Word applications.
www.OnBarcode.com
//--------------------------------------------------------------------------|| // Constructor -------------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Constructor * * @param entry The Rome API's RSS Entry representation * @throws IllegalArgumentException If the entry is not specified */ RomeRssEntry(final SyndEntry entry) throws IllegalArgumentException { // Set properties this.author = entry.getAuthor(); final SyndContent content = entry.getDescription(); this.description = content.getValue(); this.title = entry.getTitle(); final String urlString = entry.getLink(); URL url = null; try { url = new URL(urlString); } catch (final MalformedURLException murle) { throw new RuntimeException("Obtained invalid URL from Rome RSS entry: " + entry, murle); } this.url = url; } //--------------------------------------------------------------------------|| // Required Implementations ------------------------------------------------|| //--------------------------------------------------------------------------|| /* (non-Javadoc) * @see org.jboss.ejb3.examples.ch07.rsscache.spi.RssEntry#getAuthor() */ @Override public String getAuthor() { return this.author; } /* (non-Javadoc) * @see org.jboss.ejb3.examples.ch07.rsscache.spi.RssEntry#getDescription() */ @Override public String getDescription() { return this.description; }
Painting Code39 In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create Code 39 Extended image in ASP.NET applications.
www.OnBarcode.com
EAN-13 Supplement 5 Maker In VB.NET
Using Barcode generator for .NET Control to generate, create GS1 - 13 image in .NET framework applications.
www.OnBarcode.com
508 | Appendix D: Singleton Session EJB: RSS Cache Example
UCC - 12 Maker In None
Using Barcode printer for Microsoft Word Control to generate, create Universal Product Code version A image in Word applications.
www.OnBarcode.com
ECC200 Decoder In VB.NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
/* (non-Javadoc) * @see org.jboss.ejb3.examples.ch07.rsscache.spi.RssEntry#getTitle() */ @Override public String getTitle() { return this.title; } /* (non-Javadoc) * @see org.jboss.ejb3.examples.ch07.rsscache.spi.RssEntry#getUrl() */ @Override public URL getUrl() { return ProtectExportUtil.copyUrl(this.url); } //--------------------------------------------------------------------------|| // Overridden Implementations ----------------------------------------------|| //--------------------------------------------------------------------------|| /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(this.getTitle()); sb.append(" - "); sb.append(this.url.toExternalForm()); return sb.toString(); }
Barcode Printer In .NET
Using Barcode generation for .NET framework Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
EAN / UCC - 14 Printer In None
Using Barcode generator for Software Control to generate, create EAN / UCC - 14 image in Software applications.
www.OnBarcode.com
}
RssCacheBean.java
package org.jboss.ejb3.examples.ch07.rsscache.impl.rome; import import import import import import import import import import import java.io.IOException; java.net.URL; java.util.ArrayList; java.util.Collections; java.util.List; javax.annotation.PostConstruct; javax.ejb.ConcurrencyManagement; javax.ejb.ConcurrencyManagementType; javax.ejb.Lock; javax.ejb.LockType; javax.ejb.Remote;
import javax.ejb.Singleton; import javax.ejb.Startup; import org.jboss.ejb3.examples.ch07.rsscache.spi.RssCacheCommonBusiness; import org.jboss.ejb3.examples.ch07.rsscache.spi.RssEntry; import org.jboss.logging.Logger; import import import import import import com.sun.syndication.feed.synd.SyndEntry; com.sun.syndication.feed.synd.SyndFeed; com.sun.syndication.fetcher.FeedFetcher; com.sun.syndication.fetcher.FetcherException; com.sun.syndication.fetcher.impl.HttpClientFeedFetcher; com.sun.syndication.io.FeedException;
/** * Singleton EJB, to be eagerly instantiated upon application deployment, * exposing a cached view of an RSS Feed * * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a> */ @Singleton @Startup @Remote(RssCacheCommonBusiness.class) // Explicitly declare Container Managed Concurrency, which is unnecessary; it's the default @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) public class RssCacheBean implements RssCacheCommonBusiness { //--------------------------------------------------------------------------|| // Class Members -----------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Logger */ private static final Logger log = Logger.getLogger(RssCacheBean.class); //--------------------------------------------------------------------------|| // Instance Members --------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * URL pointing to the RSS Feed */ private URL url; /** * Cached RSS Entries for the feed */ private List<RssEntry> entries;
510 | Appendix D: Singleton Session EJB: RSS Cache Example
//--------------------------------------------------------------------------|| // Required Implementations ------------------------------------------------|| //--------------------------------------------------------------------------|| /* (non-Javadoc) * @see org.jboss.ejb3.examples.ch07.rsscache.spi.RssCacheCommonBusiness#get Entries() */ @Override @Lock(LockType.READ) public List<RssEntry> getEntries() { return entries; } /* (non-Javadoc) * @see org.jboss.ejb3.examples.ch07.rsscache.spi.RssCacheCommonBusiness#get Url() */ @Lock(LockType.READ) @Override public URL getUrl() { // Return a copy so we don't export mutable state to the client return ProtectExportUtil.copyUrl(this.url); } /** * @see org.jboss.ejb3.examples.ch07.rsscache.spi.RssCacheCommonBusiness #refresh() * @throws IllegalStateException If the URL has not been set */ @PostConstruct @Override // Block all readers and writers until we're done here; Optional metadata, WRITE is the default @Lock(LockType.WRITE) public void refresh() throws IllegalStateException { // Obtain the URL final URL url = this.url; if (url == null) { throw new IllegalStateException("The Feed URL has not been set"); } log.info("Requested: " + url); // Obtain the feed final FeedFetcher feedFetcher = new HttpClientFeedFetcher(); SyndFeed feed = null;
try {
feed = feedFetcher.retrieveFeed(url); } catch (final FeedException fe) { throw new RuntimeException(fe); } catch (final FetcherException fe) { throw new RuntimeException(fe); } catch (final IOException ioe) { throw new RuntimeException(ioe); } // Make a new list for the entries final List<RssEntry> rssEntries = new ArrayList<RssEntry>(); // For each entry @SuppressWarnings("unchecked") // The Rome API doesn't provide for generics, so suppress the warning final List<SyndEntry> list = (List<SyndEntry>) feed.getEntries(); for (final SyndEntry entry : list) { // Make a new entry final RssEntry rssEntry = new RomeRssEntry(entry); // Place in the list rssEntries.add(rssEntry); log.debug("Found new RSS Entry: " + rssEntry);
}
// Protect the entries from mutation from exporting the client view final List<RssEntry> protectedEntries = Collections.unmodifiableList (rssEntries); // Set the entries in the cache this.entries = protectedEntries;
}
//--------------------------------------------------------------------------|| // Internal Helper Methods -------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Sets the URL pointing to the feed * * @param url * @throws IllegalArgumentException If the URL is null */ void setUrl(final URL url) throws IllegalArgumentException { // Set the URL
Copyright © OnBarcode.com . All rights reserved.