Strategy for integrating a custom layer of web services?

Hi all,

I have built a rails application with a custom layer of web and media
services with different features.

First, there is a data retrieval service which works in the following
steps:
- On rails startup, one autonomous thread is instantiated for each
service (we work with JRuby for performance reasons).
- Data and atimes are stored in rails synchronized memory store, and
threads activate themselves or adjust their delay (from 10 to 1
second) when clients connect to the site and start sending Ajax
requests (every second).

We do this because we want to save on bandwith (it is still huge files
even though we moved from xml to json) and limit the computing
capacity needed for these services (on the data sources).

Second, the system talks to a REST API on these data sources but we
sometimes have to keep some kind of stateful representation of the
data sources because depending on the context some calls should not be
forwarded (FSM-like behavior). I will also have to implement an
exclusive lock system because in some cases it is required that only
one client at a time is able to talk to this API.

Third, we need to be able to control an MJPG streaming server (written
in Ruby as well) that serves video streams to custom Flash clients.

So this services layer is currently implemented as a small framework
in its own right and everything is initialized when rails starts. The
reason for that is that I had to develop everything under severe time
constraints.

Now that the doability of the project has been validated and we will
very likely stick with rails, I am looking for ways to better
integrate all these components with rails but I do not really know
where to start. Should I pluginify as much as possible? Should I
create some kind of LiveDataEntity - View - Controller apps? Do my
requirements necessitate to extend rails itself or is there already
some clean way to satisfy them?

Any thoughts welcome.

Thanks.

Difficult to tell what your requirements are except for "integrate all
these components with rails".