class Citrus::Common::Service::BackendSessionService

BackendSessionService

Constants

EXPORTED_FIELDS

Public Class Methods

new(app) click to toggle source

Initialize the service

@param [Object] app

# File lib/citrus/common/service/backend_session_service.rb, line 26
def initialize app
  @app = app
end

Public Instance Methods

bind(frontend_id, sid, uid, &block) click to toggle source

Bind the session with the specified user id

@param [String] frontend_id @param [Integer] sid @param [String] uid

# File lib/citrus/common/service/backend_session_service.rb, line 95
def bind frontend_id, sid, uid, &block
  namespace = 'sys'
  service = 'sessionRemote'
  method = 'bind'
  args = [sid, uid]
  rpc_invoke(frontend_id, namespace, service, method, args, &block)
end
create(args={}) click to toggle source

Create a new backend session

@param [Hash] args

# File lib/citrus/common/service/backend_session_service.rb, line 33
def create args={}
  if args.empty?
    throw Exception.new 'args should not be empty'
  end
  BackendSession.new args, self
end
get(frontend_id, sid, &block) click to toggle source

Get backend session by frontend server id and session id

@param [String] frontend_id @param [Integer] sid

# File lib/citrus/common/service/backend_session_service.rb, line 44
def get frontend_id, sid, &block
  namespace = 'sys'
  service = 'sessionRemote'
  method = 'getBackendSessionBySid'
  args = [sid]
  rpc_invoke(frontend_id, namespace, service, method,
          args, &backend_session_cb.bind(nil, block))
end
get_by_uid(frontend_id, uid, &block) click to toggle source

Get backend sessions by frontend server id and user id

@param [String] frontend_id @param [String] uid

# File lib/citrus/common/service/backend_session_service.rb, line 57
def get_by_uid frontend_id, uid, &block
  namespace = 'sys'
  service = 'sessionRemote'
  method = 'getBackendSessionByUid'
  args = [uid]
  rpc_invoke(server_id, namespace, service, method,
          args, &backend_session_cb.bind(nil, block))
end
kick_by_sid(frontend_id, sid, &block) click to toggle source

Kick a session by session id

@param [String] frontend_id @param [Integer] sid

# File lib/citrus/common/service/backend_session_service.rb, line 70
def kick_by_sid frontend_id, sid, &block
  namespace = 'sys'
  service = 'sessionRemote'
  method = 'kickBySid'
  args = [sid]
  rpc_invoke(frontend_id, namespace, service, method, args, &block)
end
kick_by_uid(frontend_id, uid, &block) click to toggle source

Kick sessions by user id

@param [String] frontend_id @param [String] uid

# File lib/citrus/common/service/backend_session_service.rb, line 82
def kick_by_uid frontend_id, uid, &block
  namespace = 'sys'
  service = 'sessionRemote'
  method = 'kickByUid'
  args = [uid]
  rpc_invoke(frontend_id, namespace, service, method, args, &block)
end
push(frontend_id, sid, key, value, &block) click to toggle source

Push the specified customized change to the frontend internal session

@param [String] frontend_id @param [Integer] sid @param [String] key @param [Hash] value

# File lib/citrus/common/service/backend_session_service.rb, line 122
def push frontend_id, sid, key, value, &block
  namespace = 'sys'
  service = 'sessionRemote'
  method = 'push'
  args = [sid, key, value]
  rpc_invoke(frontend_id, namespace, service, method, args, &block)
end
push_all(frontend_id, sid, settings, &block) click to toggle source

Push all the customized changes to the frontend internal session

@param [String] frontend_id @param [Integer] sid @param [Hash] settings

# File lib/citrus/common/service/backend_session_service.rb, line 135
def push_all frontend_id, sid, settings, &block
  namespace = 'sys'
  service = 'sessionRemote'
  method = 'pushAll'
  args = [sid, settings]
  rpc_invoke(frontend_id, namespace, service, method, args, &block)
end
unbind(frontend_id, sid, uid, &block) click to toggle source

Unbind the session with the specified user id

@param [String] frontend_id @param [Integer] sid @param [String] uid

# File lib/citrus/common/service/backend_session_service.rb, line 108
def unbind frontend_id, sid, uid, &block
  namespace = 'sys'
  service = 'sessionRemote'
  method = 'unbind'
  args = [sid, uid]
  rpc_invoke(frontend_id, namespace, service, method, args, &block)
end

Private Instance Methods

backend_session_cb(block, err, sinfos) click to toggle source

Backend session callback

@param [#call] block @param [Object] err @param [Hash, Array] sinfos

@private

# File lib/citrus/common/service/backend_session_service.rb, line 152
def backend_session_cb block, err, sinfos
  if err
    block.respond_to? :call and block.call err
    return
  end

  unless sinfos
    block.respond_to? :call and block.call
    return
  end
  sessions = []
  if sinfos.instance_of? Array
    # get_by_uid
    sinfos.each { |sinfo| sessions << create(sinfo) }
  else
    # get
    sessions = create sinfos
  end
  block.respond_to? :call and block.call nil, sessions
end
rpc_invoke(frontend_id, namespace, service, method, args, &block) click to toggle source

Rpc invoke

@param [String] frontend_id @param [String] namespace @param [String] service @param [String] method @param [Array] args

@private

# File lib/citrus/common/service/backend_session_service.rb, line 182
def rpc_invoke frontend_id, namespace, service, method, args, &block
  @app.rpc_invoke(frontend_id, {
    :namespace => namespace,
    :service => service,
    :method => method,
    :args => args
  }, &block)
end