Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
choose port dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
mattvonrocketstein committed Jan 30, 2013
1 parent 3ddea17 commit bf8678d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
11 changes: 6 additions & 5 deletions lib/cortex/services/web/__init__.py
Expand Up @@ -17,7 +17,6 @@
from cortex.mixins import LocalQueue
from cortex.util.decorators import constraint
from cortex.mixins.flavors import ThreadedIterator

from cortex.services.web.resource import ObjResource, EFrame
from cortex.services.web.resource.conf import ConfResource
from cortex.services.web.resource.root import Root
Expand All @@ -29,11 +28,11 @@
from cortex.services.web.util import draw_ugraph

from .eventhub import EventHub
from .pchoose import PortChooser

class WebRoot(Agent):
class WebRoot(Agent, PortChooser):
""" abstraction for / """

port = 1338

def iterate(self):
""" WebRoot is a trivial Agent with no true concurrency
Expand Down Expand Up @@ -115,8 +114,10 @@ def populate_chldren(self):
self.putChild('universe', ObjResource(self.universe))

# the event frame
self.putChild('eframe', EFrame())

eframe = EFrame()
self.putChild('eframe', eframe)
eframe.universe=self.universe#.host,self.ehub.port,chan),)
eframe.ehub = self.parent.filter_by_type(EventHub)[0]
# self-host the source code that's running everything.
# really just an example of how to use static.File.
src_dir = os.path.dirname(cortex.__file__)
Expand Down
9 changes: 3 additions & 6 deletions lib/cortex/services/web/eventhub/__init__.py
Expand Up @@ -11,19 +11,16 @@
from cortex.mixins.flavors import ThreadedIterator
from cortex.agents.eventhandler import AbstractEventHandler

from cortex.services.web.pchoose import PortChooser

URL_T = 'http://{host}:{port}/event/{chan}'

@ThreadedIterator.from_class
class EventHub(AbstractEventHandler):
class EventHub(AbstractEventHandler,PortChooser):

POST_HDR = { 'Content-Type':
"application/x-www-form-urlencoded;charset=utf-8" }

@property
def port(self):
""" TODO: count upwards """
return 1339

def handle_event(self, e):
""" """
args, kargs = e
Expand Down
7 changes: 6 additions & 1 deletion lib/cortex/services/web/resource/__init__.py
Expand Up @@ -30,7 +30,12 @@

class EFrame(Resource):
def render_GET(self, request):
ctx = dict(chan=request.args['chan'][0])
chan = request.args['chan'][0]
ctx = dict(eframe_url=
'http://{0}:{1}/alerts?{2}'.format(self.universe.host,
self.ehub.port,chan),)
#,#http://localhost:1339/alerts?{{chan}}
#chan=chan)
t = template('eframe')
return str(t.render(**ctx))

Expand Down
3 changes: 2 additions & 1 deletion lib/cortex/services/web/templates/eframe.html
Expand Up @@ -8,7 +8,8 @@
</tr>
<tr style="border-top:1px dotted black;">
<td colspan=2>
<iframe src="http://localhost:1339/alerts?{{chan}}"
<small>eframe: {{eframe_url}}</small>
<iframe src="{{eframe_url}}"
style="width:100%;height:150px;border:1px solid red;">
</iframe>
</td>
Expand Down
12 changes: 11 additions & 1 deletion lib/cortex/services/web/templates/objects/memory.html
Expand Up @@ -33,7 +33,17 @@ <h4>Status:</h4><hr/>
<td>
<strong>owner</strong>
</td>
<td>{{obj.owner}}</td>
<td>
<a href="owner/">
{{obj.owner.__class__.__name__.replace('<','(').replace('>',')')}}
</a>
</td>
</tr>
<tr>
<td>
<strong>length:</strong>
</td>
<td>{{obj.tspace.__len__()}}</td>
</tr>
{%block extra_status%}
{%endblock%}
Expand Down

0 comments on commit bf8678d

Please sign in to comment.