The Roller Weblogger - Triangle Java Users Group

Download Report

Transcript The Roller Weblogger - Triangle Java Users Group

Weblogs and Java
Dave Johnson
Roller Weblogger project
Prepared for the Triangle Java User’s Group
February 16th, 2004
0 - Today’s talk

What’s a weblog and why have weblogs become
such an important part of the Java community?

How you can use weblogs in software
development projects.

And about the XDoclet-driven architecture of the
Roller Weblogger.
What is a weblog?
“Weblogs are often-updated sites that point to
articles elsewhere on the web, often with
comments, and to on-site articles.”
– Dave Winer
“A blog is a web page made up of usually short,
frequently updated posts that are arranged
chronologically—like a what's new page or a journal. The
content and purposes of blogs varies greatly—from links
and commentary about other web sites, to news about a
company/person/idea, to diaries, photos, poetry, miniessays, project updates, even fiction.”
- The Blogger.com site
History of weblogging

One could consider the “what’s new” pages at CERN,
NCSA, and Netscape in the early 1990’s to be the first
weblogs.

The term weblog originated in late 1997, there were only
a couple dozen such sites then.

Radio, Blogger, LiveJournal services sprang up during
the 1999-2001 dot-com boom.

2002-2003 brings war-blogs, mainstream media blogs,
mo-blogging, and political campaign blogs.
1 - The Java weblog community

2002: a couple Java blogs and FreeRoller

2003: explosion of Java blogs
 Thousands
of JRoller Java blogs
 Hundreds of independently hosted Java blogs
 Javablogs.com community aggregator
 Sun’s Java.NET weblogs
 JBoss blogs, Codehaus blogs, etc.
JRoller.com

Free Java-oriented
weblogging service

Started as FreeRoller
by Anthony Eden in
2002.

Javalobby took over in
October 2003, rebranded, and now
hosts more than 2000
blogs.
Javablogs.com

Hub of the Java
weblogging
community.

Started by Atlassian,
makers of JIRA issue
tracking software.

Anybody can register
a weblog here, but
non-Java blogs are
discouraged.
Sun’s Java.NET community site

Launched just
before JavaONE in
July 2003

Weblogs and Wiki
are prominently
featured

Java gurus invited
to populate weblogs
Java news you can use…
http://www.thauvin.net/blog/
Fresh Java links everyday from Erik
Thauvin, featured in JDJ
http://www.beust.com/weblog/
S/W dev. discussion from Cedric
Buest, Senior S/W Engineer, BEA
http://www.raibledesigns.com
Struts, XHTML, CSS, JavaScript tips,
and Java webapp tips from Matt Raible
http://jroller.org/page/cpurdy
S/W dev. discussion from Cameron
Purdy, CEO Tangosol
http://www.simongbrown.com/blog/
JSP and J2EE webapp tips from WROX
author Simon Brown
http://fishbowl.pastiche.org/
S/W dev. discussion from Charles
Miller of Atlassian.
http://www.russellbeattie.com/notebook/
Mobile app. dev. trends from Russell
Beattie
And of course:
http://jroller.com
http://javablogs.com
http://weblogs.java.net
http://www.neward.net/ted/weblog
Ted Neward published a rough draft of
Effective Enterprise Java on his blog
2 – Weblog software features

We already discussed the basics. A weblog is:
 An
online journal, news site, diary
 A personal publishing system
 Entries in reverse chronological order

Let’s discuss how weblog software makes it easy
to write online.
Easy to update your site

Easy to add a new
weblog entry, even if
you have no
knowledge of HTML.

Easy to categorize
posts.

Easy to edit old posts.

Use a WYSIWYG
editor, HTML, or use
Wiki syntax.
Common features

Permalinks: every post gets it’s own unique and permanent URL.

Comments: Some weblogs allow comments on each post, some do
not – it’s up to the author.

RSS Newsfeeds: so that “subscribers” may read your weblog in a
Newsreader.

Page Templates: so you can customize the look, feel, and layout of
your weblog.

Referrer Tracking and Trackback: so you know who is writing
about or linking to your weblog entries.

Blog-rolling: displaying a list of favorite weblogs and websites.
Anatomy of a weblog
3 - Weblog infrastructure

Weblogging is supported by an extensive
infrastructure that is built around:
 Data formats: RSS, Atom, OPML
 Web service APIs: Blogger API, Atom
 And

good old HTTP
Let’s talk about that infrastructure and the
applications that build upon it to support
weblogging…
Newsfeed syndication

A newsfeed is simply an XML representation of
titles and entries from a website, made available
at a URL.


A weblog page: http://jroller.com/page/fate
A weblog RSS feed: http://jroller.com/rss/fate

Most newsfeeds are RSS or RDF.

Serious weblog readers use newreaders: on
JRoller over 70% of requests come from
newsreader software.
Example RSS newsfeed
XML-RPC interface

XML-RPC based Blogger API allows posting and
editing of weblog entries from weblog client
software.

MetaWeblog API adds support for titles.

XML-RPC was invented to serve this purpose.

History of weblog APIs:
http://www.xml.com/pub/a/2003/10/15/dive.html
Clients

Blog clients allow you to:
 Post
to your own weblog
 Post comments to other weblogs

Newsreader clients, allow you to:
 Subscribe
to and read RSS newsfeeds
 Import/export subscription lists as OPML
SharpReader – desktop newsreader
http://sharpreader.com
Bloglines.com – web newsreader
http://bloglines.com
w:bloggar – blogging client
http://www.wbloggar.com
4 – Weblogs & communities
“the web grows communities, almost
without trying, because the web is the
only media that allows it’s users to
communicate with each other directly,
publicly, and immediately”
- Derek Powazek, Design for Communities

Communities are important to technology development
and adoption.

Weblogs are not the only technology that enable online
community, communication, and collaboration.

What’s so special about weblogs in community building?
Weblogs vs. email

A mailing-list is also a great place
for community discussion, but flames
and noise can be a problem.

Spam is making e-mail less and less
valuable.

Email can complement weblogs



Blogging via e-mail
Mailing-list to weblog gateways
Comment notification via email
Email publishes to a
select group, the
content is free-form,
haphazard, and
unrestricted. The
problem is that email
has little "memory"
(you cant refer to a
previous email) and no
permanence (an email
doesn't park itself on
your intranet, to be
seen, shared,
repurposed, etc.. for
later use).
-Jordan Frank, Traction
Software
Weblogs vs. newsgroups

Threaded newsgroups and web forums are a great
place for community discussions, but flames and noise
can drive people away.

You can opt-out with a kill file.

Weblogs provide an opt-in model – you only read,
subscribe, and link to blogs you like. This also provides
filtering.

Forums can complement weblogs – a threaded forum
could be used for weblog comments.
Weblogs vs. web pages

Project and group web pages always
seem to grow stale.

Generally speaking, web pages are
static and difficult to update.

This is true even in a web savvy group
with great web design/editing tools.

Weblogs are easy to keep up to date and
require no special publishing tools.

Weblogs replace “homepages”
The vanity page is
dead; long live the
Blog. The vanity
Web page has lost
momentum. People
who posted one
have already done
so, and the growth
has slowed. Most
are uninteresting
and uninspired. Cat
pictures dominate
too many of them.
– John Dvorak
Weblogs vs. Wikis

Wikis provide:
 A collaborative
space for a community
 Anybody can edit or add any page via web interface
 Super simple syntax means, no need for HTML

Wikis can function as weblogs and can produce
RSS feeds

Wikis & weblogs are easily integrated
Weblog as community
“it’s this multitude [of separate sites] that gives
the weblog community model it’s strength.
Because a person has control over his own
piece of community landscape, he feels a
powerful ownership of his space that’s lacking in
traditional community sites.”
Design For Community, Derek Powazek
http://www.powazek.com/
Weblog Community Aggregators
Javablogs.com
is not the only one…
“A Community Aggregator is a portal-like web application
that displays weblog posts from a group of closely
related but separately hosted weblogs and provides
synthetic newsfeeds so that readers may subscribe to
the group as a whole.”
Enabled
by RSS syndication
Provide aggregated RSS feeds
Subscription lists in OPML format
Planet Apache

Community
aggregator for Apache
developer weblogs.

Similar sites for:








Dot Net blogs
Python blogs
GNOME blogs
Mono blogs
Fedora blogs
Debian blogs
Lisp blogs
Etc. …
Question #1

Why have weblogs have become such an
important part of the Java community?
 Ease
 This
of publishing empowers developers to share
resulted in lots of great developer weblogs
 Weblogs
are great for community building
5 – Weblogs at work

More and more people are discovering
weblogs and wikis are useful on the job
and behind the firewall.

Let’s talk about some specific uses for
weblogs in the workplace.
K-logging
http://groups.yahoo.com/group/klogs

K-logs: weblogs for knowledge management, a term
originated by Jon Robb former CEO of UserLand.

Every employee blogs on a daily basis


Goals and progress
Opinions and links to outside news and analysis

Managers subscribe to employee weblogs, directors
subscribe to their manager, and so on up the chain.

Weblog archives act as knowledge base that may be
commented upon and linked to.
It all sounds so good, but…
Will it work?
 Local blogger Mark Pilgrim points out that:

 “most
people are not good writers”
 “most
companies don’t see the value of having people
document anything”
 “most
people are not passionate about their work”
 “people
only have so much writing in them everyday”
Enterprise blogging use-cases

Enterprise Weblogging vendor Traction software suggests
a number of use cases for weblogs behind the firewall:







Personal notebook
Corporate communications
Program management
Product management
Operations log
Internal news
Communities of interest
Enterprise Blogging
Email to weblog
Email server
Email digests, notification
of comments
Email program
Portal view of aggregated
blogs and feeds
Issue tracker
Nina’s blog
Web browser
Status reports only
Wiki
Otto’s blog
Bob’s blog
Build system
Newsreader
Dev Team A’s
weblog server
Director’s blog
Assistant's blog
Tech news
External newsfeeds
Science news
Market analysis
Corporate Library’s
weblog server
Division X’s
weblog server
In my experience…

Weblogs are useful for timely news and status
 Announce
new builds and new documents
 News of big changes to code-base
 Weekly or daily status reports

Wikis are useful as collaborative space
 Serves
as software project homepage
 Record rough specs and feature ideas
 Consultants can document progress and issues
 Testers can document ever changing test setups
6 – Roller demo
Making a post with Roller
 Making a post with w:bloggar
 Using Roller’s Wiki integration features
 Managing categories
 Managing bookmarks

7 – Roller Architecture

Roller is an open source J2EE weblogging
system that manages weblog data in a
relational database.
UI – Struts and JSP
 Page and RSS rendering – Velocity
 Database access – Hibernate (or Castor)
 Editor
Layered architecture
Browser
HTML
HTTP
Newsreader
RSS
HTTP
Blog client
Presentation
Layer
Business
Layer
Persistence
Layer
XML-RPC
HTTP
Struts, JSP
Velocity
XML-RPC
Hibernate or
Castor
DBMS
7.1 Roller Persistence Layer
PersistenceStrategy <<interface>>
PersistentObject load(String id, Class c)
void store(PersistentObject o)
void remove(PersistentObject o)
void remove(String id, Class c)
void begin()
void commit()
void rollback()
QueryFactory getQueryFactory()
Query <<interface>>
List execute()
void setWhere(Condition c)
void setLimit(int limit)
void setOrderBy(Operator op, String field)
Creates
Creates
QueryFactory <<interface>>
Query createQuery(String className)
Condition createCondition(String field, Operator op, Object value)
Condition createCondition(Condition c1, BooleanOperator op, Condition c2)
Condition createCondition(BooleanOperator op, List conditions)
Persistence Layer in context
Presentation Layer
Business Layer
XML-RPC
Servlet
Uses
Uses
Uses
Weblog Page &
RSS Servlets
Struts Actions,
Forms, JSP pages
Persistence Layer
Org.roller.pojos
Creates, returns,
stores, retrieves
Org.roller.persistence
Uses
Velocity
org.roller.model
org.roller.business
Org.roller
.persistence
.hibernate
Org.roller
.persistence
.castor
Uses
Uses
Uses
Lucene
Hibernate
Castor-JDO
Uses
Struts
Uses
CacheFilter
OSCache
JDBC
JDBC
DBMS
Example code: a query
// Find all entries in a website since a given date
QueryFactory factory = mStrategy.getQueryFactory();
Query query = factory.createQuery(WeblogEntryData.class.getName());
Condition specifiedWebsite =
factory.createCondition("website", Query.EQ, website);
Condition specifiedDate = factory.createCondition(
“pubTime", Query.GT, date);
List conditions = new LinkedList();
conditions.add(specifiedWebsite);
conditions.add(specifiedDate);
query.setWhere(factory.createCondition(Query.AND, conditions));
List entries = query.execute();
7.2 Roller Business Layer


Defined by set of manager interfaces.
And a set of persistent domain objects.
org.roller.pojos
org.roller.model
UserManager
User
WeblogEntry
Category
Website
WeblogManager
Folder
Bookmark
Comment
Roller
BookmarkManager
RefererManager
Business Layer in context
Presentation Layer
Business Layer
XML-RPC
Servlet
Uses
Uses
Uses
Weblog Page &
RSS Servlets
Struts Actions,
Forms, JSP pages
Persistence Layer
Org.roller.pojos
Creates, returns,
stores, retrieves
Org.roller.persistence
Uses
Velocity
org.roller.model
Uses
Struts
org.roller.business
Org.roller
.persistence
.hibernate
Org.roller
.persistence
.castor
Uses
Uses
Hibernate
Castor-JDO
Uses
CacheFilter
OSCache
Uses
Lucene
JDBC
JDBC
DBMS
Roller Data Model
webpage
rolleruser
website
weblogentry
comment
category
categoryassoc
folder
userrole
bookmark
referer
folderassoc
Example POJO: XDoclet markup
/**
* @castor.class name="website" table="website" id="id"
*
key-generator="UUID" auto-complete="true"
* @hibernate.class table="website"
* @struts.form include-all="true"
*/
public class WebsiteData extends org.roller.persistence.PersistentObject
implements java.io.Serializable {
/**
* @castor.field set-method="setDescription"
* @castor.field-sql name="description"
*
dirty="check" sql-dirty="check"
* @hibernate.property column="description"
*
non-null=“false" unique="false"
*/
public java.lang.String getDescription() {
return this.description;
}
public void setDescription(java.lang.String description) {
this.description = description;
}
XDoclet code generation, part I
EJBDoclet
Castor O/R
mapping config
Marked-up
POJO classes
Struts Form
Beans
HibernateDoclet
Hibernate O/R
mapping config
XDoclet makes it easy to keep O/R mapping files in sync with Java source code.
7.3 Roller Presentation Layer

Editor UI implemented with Struts and JSP,
using Struts form beans generated by XDoclet.

JSP pages use:
 Struts
HTML form tags
 JSTL core and I18N tags
 Custom Roller JSP tags

Roller pages and RSS feeds are implemented
using Velocity templates.
Presentation Layer in context
Presentation Layer
Business Layer
XML-RPC
Servlet
Uses
Uses
Uses
Weblog Page &
RSS Servlets
Struts Actions,
Forms, JSP pages
Persistence Layer
Org.roller.pojos
Creates, returns,
stores, retrieves
Org.roller.persistence
Uses
Velocity
org.roller.model
Uses
Struts
org.roller.business
Org.roller
.persistence
.hibernate
Org.roller
.persistence
.castor
Uses
Uses
Hibernate
Castor-JDO
Uses
CacheFilter
OSCache
Uses
Lucene
JDBC
JDBC
DBMS
Example Action: XDoclet markup
/**
* @struts.action path="/BookmarkSave" name="bookmarkFormEx"
*
validate="true" input="/BookmarkEdit.do“
*
* @struts.action-forward name="Bookmarks"
*
path="/Bookmarks.do?method=selectFolder"
*/
public class BookmarkSave extends Action
{
public ActionForward execute(
ActionMapping
mapping,
ActionForm
actionForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
. . .
XDoclet code generation, part II
Struts Form
Beans
web.xml
WebDoclet
struts-config.xml
roller.tld
Struts Actions
Validation.xml
Servlets
Custom
JSP Tags
XDoclet makes it easy to keep deployment descriptors in sync with Java source code.
7.4 Roller Page Rendering

Weblog users want almost complete control over
page layout and design

For a variety of reasons, we can’t allow them to
edit JSP files

Instead, pages are defined by Velocity templates
 PageServlet
renders user-defined pages
 FlavorServlet renders predefined formats
Example:
<html>
<head>
<title>#showWebsiteTitle()</title>
<style type="text/css">#includePage("_css")</style>
#showRSSAutodiscoveryLink()
<script type="text/javascript" src="$ctxPath/theme/scripts/roller.js">
</script></head>
<body>
<table border="0" align="center" width="95%"><tbody><tr>
<td class="entries" width="80%" valign="top" bgcolor="#ffffff">
<h1>#showWebsiteTitle()</h1>
<p class="descrip">#showWebsiteDescription()</p>
#showWeblogCategoryChooser()<br>
#showWeblogEntries("_day" 15)
</td>
<td width="20%" valign="top" bgcolor="#ffffff" width="20%">
<h2>Calendar</h2>
#showWeblogCalendar()<br>
<h2>RSS Feeds</h2>
#showRSSBadge()<br>
#showRSSLinks()
<h2>Links</h2>
#showBookmarks("Blogroll" true false)<br>
#showBookmarks("News" true false)
<h2>Navigation</h2>
#showBasicNavBar(true)<br>
#showEditorNavBar(true)<br>
<h2>Referers</h2>
#showReferers(30 20)
</td>
</tr></tbody></table>
</body>
</html>
a weblog page template
Example: a day page template
<div class="box">
<div class="entry">
#showDayPermalink( $day )
#showEntryDate( $day )
</div>
#foreach( $entry in $entries )
<p>
<a name="$entry.anchor" id="$entry.anchor"></a>
<b>$entry.title</b> #showEntryText($entry)
<span class="dateStamp">($entry.pubTime)</span>
#showEntryPermalink( $entry )
#showCommentsPageLink( $entry )
</p>
#end
#showLinkbacks( $day )
</div>
Example: the RSS template
<?xml version="1.0" encoding="utf-8"?>
<rss version="0.91">
<channel>
<title>$utilities.textToHTML($website.name,true)</title>
<link>$websiteURL</link>
<description>$utilities.textToHTML($website.description,true)</description>
<language>en-us</language>
<copyright>Copyright #formatDate("yyyy" $now)</copyright>
<managingEditor>$emailAddress</managingEditor>
<webMaster>$emailAddress</webMaster>
#set( $entries = $pageModel.getRecentWeblogEntriesArray($entryCount) )
#foreach( $entry in $entries )
<item>
<title>$utilities.textToHTML($entry.title,true)</title>
<link>$absBaseURL$entry.permaLink</link>
<description>$entry.getRss09xDescription( $entryLength )</description>
</item>
#end
</channel>
</rss>
Roller Page Velocity Servlets
VelocityServlet
Loads “flavor” templates
from Servlet context:
rss.vm, rss92.vm,
atom.vm, opml.vm, etc.
Loads user page
templates from
database
FlavorServlet
BasePageServlet
Uses
PageServlet
SearchServlet
Page Servlet mapped to /page/
Flavor Servlet mapped to /flavor/ and to /rss/
RollerResource
Loader
PreviewServlet
7.7 Roller: Lessons Learned

Initially, FreeRoller suffered from severe performance
and load-related stability problems.

Now, JRoller runs smoothly and puts minimal load on
the Java Lobby server.

Most important performance improvements
 Caching,
Caching, and more Caching
 Proper use of connections - Open Session in View
 Database Indexes
Caching, Caching, Caching

Server-side Page and RSS feed caching via OSCache

Enable client-side caching by supporting HTTP IFMODIFIED-SINCE header.

Cache last update time for each weblog so checking IFMODIFIED-SINCE needs no database query.

Caching keeps database hits to absolute minimum.
Example: RSS feed caching
IfModifed
Filter
Cache
Filter
OSCache
Servlet
Container
Page
Servlet
Velocity
Page
Business
Layer
doFilter
Get last mod
time from cache
getLastModTime
304, not modified
Return entry
from cache
doFilter
getEntry
doFilter
service
run
getEntries
Return freshly
generated page
Open Session in View

Cannot give each HTTP session it’s own database
connection – that won’t scale.

Pattern documented by Hibernate folks, a “persistence
session” corresponds to a database connection.

Each incoming request gets a connection from the
connection pool and uses it for all processing.

When response is complete, request’s connection is
returned to the pool.
Open Session in View - sequence
Servlet
Filter
Servlet
Container
Action or
Page
Business
Layer
doFilter()
begin()
doFilter()
service()
queries
inserts
updates
commit()
response
Database indexes

Biggest single performance improvement.

Watch for queries that examine lots of
rows, make sure key fields are indexed.
8 – Conclusion

Go sign up for your new blog at JRoller.com

Thanks for listening!

Any questions?