Permalink
Browse files

Stats window now retrieves BBB server IP from the same place as setip…

…, rather than just looking for the server computer's IP
  • Loading branch information...
1 parent 128bd5b commit f347a23822d03cd136a47ec35697ffc3b28f297d @jtrobinson jtrobinson committed Feb 27, 2012
@@ -34,6 +34,8 @@
@ThreadSafe
public class Poll{
+ // Poll URL http://142.204.133.24/bigbluebutton/polls.jsp?poll={webKey}
+
/* KEY PLACES TO UPDATE, WHEN ADDING NEW FIELDS TO THE HASH:
* PollService.java, getPoll()
* PollInvoker.java, invoke()
@@ -19,14 +19,15 @@
package org.bigbluebutton.conference.service.poll;
-import java.net.InetAddress;
+import java.net.*;
import java.util.List;
import org.slf4j.Logger;
import org.red5.logging.Red5LoggerFactory;
import java.util.ArrayList;
-
+import java.io.*;
+import java.util.Scanner;
import org.bigbluebutton.conference.service.poll.PollRoomsManager;
import org.bigbluebutton.conference.service.poll.PollRoom;
@@ -45,7 +46,11 @@
private static final String APP = "Poll";
private PollRoomsManager roomsManager;
private String CURRENTKEY = "bbb-polling-webID";
- private int MAX_WEBKEYS = 9999;
+ private Integer MAX_WEBKEYS = 9999;
+ private Integer MIN_WEBKEYS = 1000;
+ private String BBB_FILE = "/etc/nginx/sites-available/bigbluebutton";
+ private String BBB_SERVER_FIELD = "server_name";
+ private String BBB_PORT_FIELD = "listen";
public PollHandler handler;
@@ -61,22 +66,17 @@ public boolean destroyRoom(String name) {
return true;
}
+ // About to change dbConnect entirely, but if you can see this again you're back to normal.
public Jedis dbConnect(){
- // Reads IP from Java, for portability
- String serverIP = "INVALID IP";
- try
- {
- InetAddress addr = InetAddress.getLocalHost();
- // Get hostname
- String hostname = addr.getHostName();
- serverIP = hostname;
- }
- catch (Exception e)
- {
- log.error("IP capture failed.");
- }
- JedisPool redisPool = new JedisPool(serverIP, 6379);
- return redisPool.getResource();
+ try{
+ String serverIP = getLocalIP();
+ JedisPool redisPool = new JedisPool(serverIP, 6379);
+ return redisPool.getResource();
+ }
+ catch (Exception e){
+ log.error("Error in PollApplication.dbConnect()");
+ }
+ return null;
}
public void destroyPolls(String name){
@@ -105,7 +105,7 @@ public void cutOffWebPoll(String pollKey){
jedis.del(webKey);
}
catch (Exception e){
- log.warn("Error in deleting web key " + webKey);
+ log.error("Error in deleting web key " + webKey);
}
}
@@ -118,7 +118,7 @@ public boolean addRoomListener(String room, IPollRoomListener listener) {
roomsManager.addRoomListener(room, listener);
return true;
}
- log.warn("Adding listener to a non-existant room " + room);
+ log.error("Adding listener to a non-existant room " + room);
return false;
}
@@ -158,29 +158,114 @@ public void setStatus(String pollKey, Boolean status){
pollRecorder.setStatus(pollKey, status);
}
- public String generate(String pollKey){
+ public ArrayList generate(String pollKey){
Jedis jedis = dbConnect();
if (!jedis.exists(CURRENTKEY)){
- jedis.set(CURRENTKEY, "0");
+ Integer base = MIN_WEBKEYS -1;
+ jedis.set(CURRENTKEY, base.toString());
}
// The value stored in the bbb-polling-webID key represents the next available web-friendly poll ID
+ ArrayList webInfo = new ArrayList();
+
String nextWebKey = webKeyIncrement(Integer.parseInt(jedis.get(CURRENTKEY)), jedis);
jedis.del(nextWebKey);
jedis.set(nextWebKey, pollKey);
// Save the webKey that is being used as part of the poll key, for quick reference later
jedis.hset(pollKey, "webKey", nextWebKey);
// Replace the value stored in bbb-polling-webID
jedis.set(CURRENTKEY, nextWebKey);
- return nextWebKey;
+ webInfo.add(nextWebKey);
+
+ String hostname = getLocalIP();
+ webInfo.add(hostname);
+
+ String hostPort = getLocalPort();
+ webInfo.add(hostPort);
+
+ return webInfo;
}
private String webKeyIncrement(Integer index, Jedis jedis){
String nextIndex;
if (++index <= MAX_WEBKEYS){
nextIndex = index.toString();
}else{
- nextIndex = "1";
+ nextIndex = MIN_WEBKEYS.toString();
}
return nextIndex;
}
+
+ private String getLocalIP()
+ {
+ File parseFile = new File(BBB_FILE);
+ try{
+ Scanner scanner = new Scanner(new FileReader(parseFile));
+ Boolean found = false;
+ String serverAddress = "";
+ while (!found && scanner.hasNextLine()){
+ serverAddress = processLine(scanner.nextLine(), BBB_SERVER_FIELD);
+ if (!serverAddress.equals(""))
+ found = true;
+ }
+ scanner.close();
+ return serverAddress;
+ }
+ catch (Exception e){
+ log.error("Error in scanning " + BBB_FILE + " to find server address.");
+ }
+ return null;
+ }
+
+ private String getLocalPort()
+ {
+ File parseFile = new File(BBB_FILE);
+ try{
+ Scanner scanner = new Scanner(new FileReader(parseFile));
+ Boolean found = false;
+ String serverAddress = "";
+ while (!found && scanner.hasNextLine()){
+ serverAddress = processLine(scanner.nextLine(), BBB_PORT_FIELD);
+ if (!serverAddress.equals(""))
+ found = true;
+ }
+ scanner.close();
+ return serverAddress;
+ }
+ catch (Exception e){
+ log.error("Error in scanning " + BBB_FILE + " to find server PORT.");
+ }
+ return null;
+ }
+
+ private String processLine(String line, String option){
+ //use a second Scanner to parse the content of each line
+ Scanner scanner = new Scanner(line);
+ if ( scanner.hasNext() ){
+ String name = scanner.next();
+ String value = scanner.next();
+ if (name.equals(option)){
+ // Return the host address without the trailing semicolon
+ return value.substring(0, value.length()-1);
+ }
+ }
+ else {
+ log.error("Error in processing server address from " + BBB_FILE);
+ }
+ return "";
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
}
@@ -94,10 +94,10 @@ public void setStatus(String pollKey, Boolean status){
application.setStatus(pollKey, status);
}
- public String generate(String pollKey){
- String webKey;
- webKey = application.generate(pollKey);
- return webKey;
+ public ArrayList generate(String pollKey){
+ ArrayList webInfo = new ArrayList();
+ webInfo = application.generate(pollKey);
+ return webInfo;
}
public void cutOffWebPoll(String pollKey){
@@ -29,6 +29,8 @@ package org.bigbluebutton.modules.polling.events
public var repost:Boolean;
public var pollKey:String;
public var poll:PollObject;
+ public var webHostIP:String;
+ public var webHostPort:String;
public function GenerateWebKeyEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)
{
@@ -101,10 +101,17 @@ package org.bigbluebutton.modules.polling.managers
public function handleReturnWebKeyEvent(e:GenerateWebKeyEvent):void
{
- if (!e.repost)
+ var transferURL:String = e.webHostIP;
+ if (e.webHostPort != "80")
+ transferURL += (":" + e.webHostPort);
+ transferURL += "/bigbluebutton/polls.jsp?poll=" + e.poll.webKey;
+
+ statsWindow.webPollUrl = transferURL;
+ if (!e.repost){
instructionsWindow._webKey = e.poll.webKey;
- else
+ }else{
statsWindow.trackingPoll.webKey = e.poll.webKey;
+ }
}
// Action makers (function that actually act on the windows )
@@ -417,10 +417,18 @@ package org.bigbluebutton.modules.polling.service
//--------------------------------------//
// Responder functions
function success(obj:Object):void{
- var webKey:String = obj as String;
+ var webInfo:Array = obj as Array;
+
+ var webKey:String = webInfo[0];
+ var webHostIP:String = webInfo[1];
+ var webHostPort:String = webInfo[2];
+
var webKeyReturnEvent:GenerateWebKeyEvent = new GenerateWebKeyEvent(GenerateWebKeyEvent.RETURN);
webKeyReturnEvent.poll = generateEvent.poll
webKeyReturnEvent.poll.webKey = webKey;
+ webKeyReturnEvent.webHostIP = webHostIP;
+ webKeyReturnEvent.webHostPort = webHostPort;
+
dispatcher.dispatchEvent(webKeyReturnEvent);
}
function failure(obj:Object):void{
Oops, something went wrong.

0 comments on commit f347a23

Please sign in to comment.