public class PluginRespirator
extends java.lang.Object
Constructor and Description |
---|
PluginRespirator(Node node,
PluginInfoWrapper pi) |
Modifier and Type | Method and Description |
---|---|
HTMLNode |
addFormChild(HTMLNode parentNode,
java.lang.String target,
java.lang.String name)
Add a valid form including the
NodeClientCore.formPassword . |
FCPPluginConnection |
connectToOtherPlugin(java.lang.String pluginName,
FredPluginFCPMessageHandler.ClientSideFCPMessageHandler messageHandler)
NOTICE: This API is a rewrite of the whole code for plugin communication.
|
HighLevelSimpleClient |
getHLSimpleClient() |
Node |
getNode()
Get the node.
|
PageMaker |
getPageMaker()
Get the PageMaker.
|
FCPPluginConnection |
getPluginConnectionByID(java.util.UUID connectionID)
Allows FCP server plugins, that is plugins which implement
FredPluginFCPMessageHandler.ServerSideFCPMessageHandler , to obtain an existing client
FCPPluginConnection by its UUID - if the client is still connected.May be used by servers which cannot store objects in memory, for example because they are using a database: An UUID can be serialized to disk, serialization would not be
possible for a FCPPluginConnection .Servers are however free to instead keep the FCPPluginConnection in memory, usage
of this function is not mandatory.Must not be used by client plugins: They shall instead keep a hard reference to the FCPPluginConnection in memory after they have received it from
connectToOtherPlugin(String,
FredPluginFCPMessageHandler.ClientSideFCPMessageHandler) . |
PluginTalker |
getPluginTalker(FredPluginTalker fpt,
java.lang.String pluginname,
java.lang.String identifier)
Deprecated.
|
SessionManager |
getSessionManager(java.lang.String cookieNamespace)
Get a new session manager for use with the global "/" cookie path and the given cookie namespace.
|
SessionManager |
getSessionManager(java.net.URI cookiePath)
Deprecated.
|
PluginStore |
getStore()
Get a PluginStore that can be used by the plugin to put data in a database.
|
SubConfig |
getSubConfig()
Get the plugin's SubConfig.
|
ToadletContainer |
getToadletContainer()
Get the ToadletContainer, which manages HTTP.
|
FilterCallback |
makeFilterCallback(java.lang.String path)
Create a GenericReadFilterCallback, which will filter URLs in
exactly the same way as the node does when filtering a page.
|
void |
putStore(PluginStore store)
This should be called by the plugin to store its PluginStore in the node's
database.
|
void |
storeConfig()
Force a write of the plugin's config file.
|
public PluginRespirator(Node node, PluginInfoWrapper pi)
public HighLevelSimpleClient getHLSimpleClient()
public Node getNode()
public FilterCallback makeFilterCallback(java.lang.String path)
path
- The base URI for the page being filtered. Not necessarily
a FreenetURI.public PageMaker getPageMaker()
public HTMLNode addFormChild(HTMLNode parentNode, java.lang.String target, java.lang.String name)
NodeClientCore.formPassword
. See the JavaDoc there for an explanation of the purpose of this mechanism.
ATTENTION: It is critically important to validate the form password when processing requests which "change the server state". Other words for this would be requests which change your database or "write" requests. Requests which only read values from the server don't have to validate the form password.
To validate that the right password was received, use WebInterfaceToadlet.isFormPassword(HTTPRequest)
.
parentNode
- The parent HTMLNode.target
- Where to post to.name
- The id/name of the form.@Deprecated public PluginTalker getPluginTalker(FredPluginTalker fpt, java.lang.String pluginname, java.lang.String identifier) throws PluginNotFoundException
connectToOtherPlugin(String,
FredPluginFCPMessageHandler.ClientSideFCPMessageHandler)
instead.PluginNotFoundException
public FCPPluginConnection connectToOtherPlugin(java.lang.String pluginName, FredPluginFCPMessageHandler.ClientSideFCPMessageHandler messageHandler) throws PluginNotFoundException
getPluginTalker(FredPluginTalker, String, String)
API meanwhile.Creates a FCP client connection with another plugin which is a FCP server (= which
implements interface FredPluginFCPMessageHandler.ServerSideFCPMessageHandler
).
Currently, the remote plugin must run in the same node, but the fact that FCP is used lays
foundation for a future implementation to allow you to connect to other plugins by network,
no matter where they are running.
The formally correct mechanism of disconnecting the returned FCPPluginConnection
is to null out the strong reference to it. The node internally keeps a ReferenceQueue
which allows it to detect the strong reference being nulled, which in turn makes the node
clean up its internal structures.
Thus, you are encouraged to keep the returned FCPPluginConnection
in memory and use
it for as long as you need it. Notice that keeping it in memory won't block unloading of the
server plugin. If the server plugin is unloaded, the send-functions will fail. To get
reconnected once the server plugin is loaded again, you must obtain a fresh client connection
from this function: Once an existing client connection is indicated as closed by a single
call to a send function throwing IOException
, it must be considered as dead
for ever, reconnecting is not possible.
While this does seem like you do not have to take care about disconnection at all, you
must make sure to not keep an excessive amount of FCPPluginConnection
objects
strongly referenced to ensure that this mechanism works. Especially notice that a
FCPPluginConnection
is safe and intended to be used for multiple messages, you should
not obtain a fresh one for every message you send.
Also, you should make sure to periodically try to send a message over the
FCPPluginConnection
and check whether you receive a reply to check whether the
connection still is alive: There is no other mechanism of indicating a closed connection to
you than not getting back any reply to messages you send. So if your plugin does send
messages very infrequently, and thus might keep a reference to a dead FCPPluginConnection for
a long time, it might be indicated to create a "keepalive-loop" which sends "ping" messages
periodically and reconnects if no "pong" message is received within a sane timeout. Whether a
server plugin supports a special "ping" message or requires you to use another type of
message as ping is left up to the implementation of the server plugin.
pluginName
- The name of the main class of the plugin - that is the class which implements
FredPlugin
. See PluginManager.getPluginInfoByClassName(String)
.messageHandler
- An object of your plugin which implements the
FredPluginFCPMessageHandler.ClientSideFCPMessageHandler
interface. Its purpose is
to handle FCP messages which the remote plugin sends back to your plugin.FCPPluginConnection
representing the client connection.PluginNotFoundException
public FCPPluginConnection getPluginConnectionByID(java.util.UUID connectionID) throws java.io.IOException
FredPluginFCPMessageHandler.ServerSideFCPMessageHandler
, to obtain an existing client
FCPPluginConnection
by its UUID
- if the client is still connected.UUID
can be serialized to disk, serialization would not be
possible for a FCPPluginConnection
.FCPPluginConnection
in memory, usage
of this function is not mandatory.FCPPluginConnection
in memory after they have received it from
connectToOtherPlugin(String,
FredPluginFCPMessageHandler.ClientSideFCPMessageHandler)
. If they did not keep a hard
reference and only stored the ID, the FCPPluginConnection
would be garbage collected
and thus considered as disconnected.FredPluginFCPMessageHandler.ServerSideFCPMessageHandler.handlePluginFCPMessage(
FCPPluginConnection, FCPPluginMessage)
for full instructions on how to handle the lifecycle
of client connections and their disconnection.connectionID
- The connection's UUID
as obtained by FCPPluginConnection.getID()
.java.io.IOException
- If there has been no client connection with the given ID or if the client has
disconnected already.UUID
as invalid forever and
discard it.The message handler at FredPluginFCPMessageHandler.ServerSideFCPMessageHandler provides
an explanation of when to use this.
public ToadletContainer getToadletContainer()
public PluginStore getStore() throws PersistenceDisabledException
storeIdentifier
- PluginStore identifier, Plugin's name or some other identifier.DatabaseDisabledException
PersistenceDisabledException
public void putStore(PluginStore store) throws PersistenceDisabledException
store
- Store to put.storeIdentifier
- Some string to identify the store, basically the plugin's name.DatabaseDisabledException
PersistenceDisabledException
@Deprecated public SessionManager getSessionManager(java.net.URI cookiePath)
SessionManager
for a detailed explanation of what cookie paths are.
The usage of the global "/" path is not allowed. You must use getSessionManager(String cookieNamespace)
if you want your cookie to be valid in the "/" path.
This function is synchronized on the SessionManager-list and therefore concurrency-proof.public SessionManager getSessionManager(java.lang.String cookieNamespace)
SessionManager
for a detailed explanation of what cookie namespaces are.
This function is synchronized on the SessionManager-list and therefore concurrency-proof.myCookieNamespace
- The name of the client application which uses this cookie.public SubConfig getSubConfig()
public void storeConfig()