javascript topic maps in server environments
DESCRIPTION
This paper is about the JavaScript-based Topic Maps Engine tmjs.TRANSCRIPT
W E B V E V E R I E T
Ravn Webveveriet AS, 2010-10-01
Jan Schreiber <[email protected]>
JavaScript Topic Maps in server environments
1
W E B V E V E R I E T
Outline
• JavaScript
• The tmjs Topic Maps engine
• Use Case: A PSI Server
• Outlook
2
W E B V E V E R I E T
JavaScript
• JavaScript is LISP with a C-like syntax
• Virtually every personal computer in the world has at least one JavaScript interpreter installed on it and in active use.
3
W E B V E V E R I E T
tmjs• A Topic Maps engine
• Written in pure JavaScript
• Full TMDM including Variants
• TMAPI 2.0-based
• In-memory backend, JTM import/export, experimental XTM 2.0 import (requires DOM)
4
W E B V E V E R I E T
tmjs• Platform independent: All modern
browsers, mobile devices (iPhone & Android), server-side JavaScript
• Unit tests, CXTM tests (partly) & JSLint validating
• Small changes to TMAPI due to the lack of method overloading
• Syntactic sugar: Supports chaining of TMAPI calls
5
W E B V E V E R I E T
Chaining
tm.createTopic().addSubjectIdentifier(foo).
createName('bar').getParent().
createOccurrence(type,'baz').
addScopingTopic(quux);
1
2
3
4
6
W E B V E V E R I E T
tmjs: Outlook• More import/export formats: XTM 2.0, CTM
• Complete TMAPI, add more tests, full CXTM
• Persistence:
• Web SQL Database backend
• Persistent backend for Node (couchdb?)
• Later: Query language
7
W E B V E V E R I E T
Use Case: A PSI Server
• Idea: Start the server with a Topic Map and it will serve information about all Subject Identifiers for a given domain
8
W E B V E V E R I E T
• Screenshot node-psi-server
9
W E B V E V E R I E T
Server-side JavaScript
• 1996: Netscape releases LiveWire as part of Netscape Enterprise Server 2.0
• 2009: Ryan Dahl writes Node
10
W E B V E V E R I E T
Node• A framework for low-level network
applications based on Google's V8 engine
• TCP, DNS and HTTP are first-class protocols
• Event-based, asynchronous programming
• All I/O is non-blocking
11
W E B V E V E R I E T
result = db_query(db, "SELECT * FROM topic");
12
W E B V E V E R I E T
db_query(db, "SELECT * FROM topic", callback);
13
W E B V E V E R I E T
db_query(db, "SELECT * FROM topic", callback);
callback = function (err, result) {
// ...
}
14
W E B V E V E R I E T
var tm, servername;
// assumes that the TopicMap object tm has been initialized and
// the topic map in question has been imported successfuly.
// servername is set from a command line parameter
http.createServer(function (req, res) {
var url = 'http://'+servername+req.url, loc, topic;
loc = tm.createLocator(url);
topic = tm.getTopicBySubjectIdentifier(loc);
if (topic) {
res.writeHead(200, {'Content-Type': 'text/html'});
// create a page with information about the PSI
} else {
// Not found: create a 404 response
}
res.close();
}).listen(80);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
15
W E B V E V E R I E T
Use Case: A PSI Server
• More output formats: XHTML, JTM, XTM
• Support for logging, caching, templates
• Configurable list of information elements that are included on generated pages (e.g. dc:description, supertype-subtype)
• PSI black-listing
• subj3ct.com integration
16
W E B V E V E R I E T
PSI Server: Observations
• Easy to implement
• It’s really fast: 200+200ms to read the Opera topic map, 1ms to serve a PSI page
• tmjs can be used on server and client side Reuse of application code
17
W E B V E V E R I E T
Summary & Outlook
• Server side Topic Maps with JavaScript: possible!
• Asynchronous TMAPI?
• In its current state maybe best suited for low-level applications
18
W E B V E V E R I E T
What could it be good for?
• TMRAP, TM REST API
• SDshare
• P2P applications
• DNS servers
19
W E B V E V E R I E T
Questions?
Download tmjs now!
http://github.com/jansc/tmjs
Coming soon:
http://github.com/jansc/node-psi-server
20