* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class NodeListDatabaseWrapper extends BaseDatabaseWrapper {
+class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerable {
// Table names
const DB_TABLE_NODE_LIST = 'node_list';
+ // Constants for column name
+ const DB_COLUMN_NODE_SESSION_ID = 'node_session_id';
+ const DB_COLUMN_NODE_IP_PORT = 'node_ipport';
+
/**
* Protected constructor
*
public final function getIndexKey () {
return $this->getDatabaseInstance()->getIndexKey();
}
+
+ /**
+ * Resolves a session id into an ip:port combination
+ *
+ * @param $sessionId A valid session id
+ * @return $recipient Recipient as ip:port combination
+ */
+ public function resolveIpPortBySessionId ($sessionId) {
+ // Set invalid ip:port combination
+ $recipient = 'invalid:invalid';
+
+ // Now get a search criteria instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for the node number zero which is hard-coded the default
+ $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID, 1);
+ $searchInstance->setLimit(1);
+
+ // Get a result back
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Is it valid?
+ if ($resultInstance->next()) {
+ // Save the result instance in this class
+ $this->setResultInstance($resultInstance);
+
+ // Get the node id from result and set it
+ $recipient = $this->getField(NodeListDatabaseWrapper::DB_COLUMN_NODE_IP_PORT);
+ } // END - if
+
+ // Return result
+ return $recipient;
+ }
}
// [EOF]