jerklib
Class Session

java.lang.Object
  extended by jerklib.Session

public class Session
extends Object

Session contains methods to manage an IRC connection. Like changeNick(String) , setRejoinOnKick(boolean) , getUserModes() etc.

Session is where Tasks and Listeners should be added to be notified of IRCEvents coming from the connected server.

You can override the default parsing and internal event handling of a Session with setInternalEventHandler(IRCEventListener) and setInternalParser(InternalEventParser).

New Session instances are obtained by requesting a connection with the ConnectionManager

Author:
mohadib
See Also:
ConnectionManager.requestConnection(String), ConnectionManager.requestConnection(String, int), ConnectionManager.requestConnection(String, int, Profile)

Nested Class Summary
static class Session.State
           
 
Method Summary
 void action(String target, String actionText)
          Send ctcp action
 void addIRCEventListener(IRCEventListener listener)
          Adds an IRCEventListener to the Session.
 void changeNick(String newNick)
          Send nick change request
 void chanList()
          Get a List of Channels from server.
 void chanList(String channel)
          Get information on a secific channel
 void close(String quitMessage)
          Disconnect from server and destroy Session
 void ctcp(String target, String request)
          Send a ctcp request
 boolean equals(Object o)
           
 Channel getChannel(String channelName)
          Gets a Channel by name
 List<Channel> getChannels()
          Get a List of Channels Session is currently in
 String getConnectedHostName()
          Returns host name this Session is connected to.
 IRCEventListener getInternalEventHandler()
          Returns the internal event handler this Session is using
 InternalEventParser getInternalEventParser()
          Gets the InternalEventParser this Session uses for event parsing
 Collection<IRCEventListener> getIRCEventListeners()
          Get a collection of all IRCEventListeners attached to Session
 String getNick()
          Nick used for Session
 RequestedConnection getRequestedConnection()
          Get RequestedConnection for Session
 ServerInformation getServerInformation()
          Get ServerInformation for Session
 void getServerVersion()
          Send server version query
 void getServerVersion(String hostPattern)
          Send server version query for specific hostmask pattern
 boolean getShouldUseAltNicks()
          Returns if Session should try alternate nicks on connection if a nick in use event is received.
 List<ModeAdjustment> getUserModes()
          returns a List of UserModes for this Session
 int hashCode()
           
 void invite(String nick, Channel chan)
          Invite a user to a channel
 boolean isAway()
          Is this Session marked away?
 boolean isChannelToken(String token)
          Test if a String starts with a known channel prefix
 boolean isConnected()
          Is this Session currently connected to an IRC server?
 boolean isLoggedIn()
          Returns true if the Session has an active Connection and has successfully logged on to the Connection.
 boolean isProfileUpdating()
          Profile is updating when a new nick is requested but has not been approved from server yet.
 boolean isRejoinOnKick()
          Should this Session rejoin channels it is Kicked from? Default is true.
 void join(String channel)
          Join a Channel
 void join(String channel, String pass)
          Join a password protected Channel
 void mode(String target, String mode)
          Set a mode
 void notice(String target, String msg)
          Send a notice
 void onEvent(Task task)
          Add a task to be ran when any IRCEvent is received
 void onEvent(Task task, IRCEvent.Type... types)
          Add a task to be ran when any of the given Types of IRCEvents are received
 boolean removeIRCEventListener(IRCEventListener listener)
          Remove IRCEventListner from Session
 List<Channel> removeNickFromAllChannels(String nick)
          Removes a nick from all channels
 void removeTask(Task t)
          Removes a Task from the Session.
 void sayChannel(Channel channel, String msg)
          Speak in a Channel
 void sayChannel(String msg, Channel channel)
          Speak in a channel
 void sayPrivate(String nick, String msg)
          Send a private message
 void sayRaw(String data)
          Send raw text to server
 void setAway(String message)
          Set self away
 void setInternalEventHandler(IRCEventListener handler)
          Sets the internal event handler this Session should use
 void setInternalParser(InternalEventParser parser)
          Sets the InternalEventParser this Session should use for event parsing
 void setRejoinOnKick(boolean rejoin)
          Sets that this Sessions should or should not rejoin Channels kiced from
 void setShouldUseAltNicks(boolean use)
          Set Session yo try alternate nicks on connection if a nick in use event is received , or not.
 void unsetAway()
          Unset away
 void unSetAway()
          Unset away
 void who(String who)
          Send Who request
 void whois(String nick)
          Send a whois query
 void whoWas(String nick)
          Send WhoWas query
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInternalEventParser

public InternalEventParser getInternalEventParser()
Gets the InternalEventParser this Session uses for event parsing

Returns:
InternalEventParser
See Also:
InternalEventParser, DefaultInternalEventParser, CommandParser

setInternalParser

public void setInternalParser(InternalEventParser parser)
Sets the InternalEventParser this Session should use for event parsing

Parameters:
parser -
See Also:
InternalEventParser, DefaultInternalEventParser, CommandParser

setInternalEventHandler

public void setInternalEventHandler(IRCEventListener handler)
Sets the internal event handler this Session should use

Parameters:
handler -
See Also:
IRCEventListener, DefaultInternalEventHandler

getInternalEventHandler

public IRCEventListener getInternalEventHandler()
Returns the internal event handler this Session is using

Returns:
event handler
See Also:
IRCEventListener, DefaultInternalEventHandler

getUserModes

public List<ModeAdjustment> getUserModes()
returns a List of UserModes for this Session

Returns:
UserModes

sayChannel

public void sayChannel(Channel channel,
                       String msg)
Speak in a Channel

Parameters:
channel -
msg -
See Also:
Channel.say(String)

isConnected

public boolean isConnected()
Is this Session currently connected to an IRC server?

Returns:
true if connected else false

isRejoinOnKick

public boolean isRejoinOnKick()
Should this Session rejoin channels it is Kicked from? Default is true.

Returns:
true if channels should be rejoined else false

setRejoinOnKick

public void setRejoinOnKick(boolean rejoin)
Sets that this Sessions should or should not rejoin Channels kiced from

Parameters:
rejoin -

isLoggedIn

public boolean isLoggedIn()
Returns true if the Session has an active Connection and has successfully logged on to the Connection.

Returns:
if logged in

setShouldUseAltNicks

public void setShouldUseAltNicks(boolean use)
Set Session yo try alternate nicks on connection if a nick in use event is received , or not. True by default.

Parameters:
use -

getShouldUseAltNicks

public boolean getShouldUseAltNicks()
Returns if Session should try alternate nicks on connection if a nick in use event is received. True by default.

Returns:
should use alt nicks

close

public void close(String quitMessage)
Disconnect from server and destroy Session

Parameters:
quitMessage -

getNick

public String getNick()
Nick used for Session

Returns:
nick

changeNick

public void changeNick(String newNick)
Send nick change request


isProfileUpdating

public boolean isProfileUpdating()
Profile is updating when a new nick is requested but has not been approved from server yet.

Returns:
true if profile is updating

isAway

public boolean isAway()
Is this Session marked away?

Returns:
true if away else false

setAway

public void setAway(String message)
Set self away


unsetAway

public void unsetAway()
Unset away


getServerInformation

public ServerInformation getServerInformation()
Get ServerInformation for Session

Returns:
ServerInformation for Session
See Also:
ServerInformation

getRequestedConnection

public RequestedConnection getRequestedConnection()
Get RequestedConnection for Session

Returns:
RequestedConnection for Session
See Also:
RequestedConnection

getConnectedHostName

public String getConnectedHostName()
Returns host name this Session is connected to. If the session is disconnectd an empty string will be returned.

Returns:
hostname or an empty string if not connected
See Also:
getRequestedConnection(), RequestedConnection.getHostName()

addIRCEventListener

public void addIRCEventListener(IRCEventListener listener)
Adds an IRCEventListener to the Session. This listener will be notified of all IRCEvents coming from the connected sever.

Parameters:
listener -

removeIRCEventListener

public boolean removeIRCEventListener(IRCEventListener listener)
Remove IRCEventListner from Session

Parameters:
listener -
Returns:
true if listener was removed else false

getIRCEventListeners

public Collection<IRCEventListener> getIRCEventListeners()
Get a collection of all IRCEventListeners attached to Session

Returns:
listeners

onEvent

public void onEvent(Task task)
Add a task to be ran when any IRCEvent is received

Parameters:
task -
See Also:
Task, TaskImpl

onEvent

public void onEvent(Task task,
                    IRCEvent.Type... types)
Add a task to be ran when any of the given Types of IRCEvents are received

Parameters:
task - - task to run
types - - types of events task should run on
See Also:
Task, TaskImpl

removeTask

public void removeTask(Task t)
Removes a Task from the Session. Some Tasks can possibly be the value for many Types.

Parameters:
t -

getChannels

public List<Channel> getChannels()
Get a List of Channels Session is currently in

Returns:
channels
See Also:
Channel

getChannel

public Channel getChannel(String channelName)
Gets a Channel by name

Parameters:
channelName -
Returns:
Channel or null if no such Channel is joined.

removeNickFromAllChannels

public List<Channel> removeNickFromAllChannels(String nick)
Removes a nick from all channels

Parameters:
nick -
Returns:
list of Channels nick was found in

isChannelToken

public boolean isChannelToken(String token)
Test if a String starts with a known channel prefix

Parameters:
token -
Returns:
true if starts with a channel prefix else false

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

who

public void who(String who)
Send Who request

Parameters:
who -

whois

public void whois(String nick)
Send a whois query

Parameters:
nick - - target of whois

whoWas

public void whoWas(String nick)
Send WhoWas query

Parameters:
nick -

invite

public void invite(String nick,
                   Channel chan)
Invite a user to a channel

Parameters:
nick -
chan -

chanList

public void chanList()
Get a List of Channels from server.


chanList

public void chanList(String channel)
Get information on a secific channel

Parameters:
channel -

join

public void join(String channel)
Join a Channel

Parameters:
channel -

join

public void join(String channel,
                 String pass)
Join a password protected Channel

Parameters:
channel -
pass -

ctcp

public void ctcp(String target,
                 String request)
Send a ctcp request

Parameters:
target -
request -

notice

public void notice(String target,
                   String msg)
Send a notice

Parameters:
target -
msg -

unSetAway

public void unSetAway()
Unset away


getServerVersion

public void getServerVersion()
Send server version query


getServerVersion

public void getServerVersion(String hostPattern)
Send server version query for specific hostmask pattern

Parameters:
hostPattern -

mode

public void mode(String target,
                 String mode)
Set a mode

Parameters:
target -
mode -

action

public void action(String target,
                   String actionText)
Send ctcp action

Parameters:
target -
actionText -

sayChannel

public void sayChannel(String msg,
                       Channel channel)
Speak in a channel

Parameters:
msg -
channel -
See Also:
Channel.say(String)

sayPrivate

public void sayPrivate(String nick,
                       String msg)
Send a private message

Parameters:
nick -
msg -

sayRaw

public void sayRaw(String data)
Send raw text to server

Parameters:
data -