Hey,
I have an interface called IFunctionDictionary which has a function called
Execute. In my main thread run() function I register few functions and
there corresponding key/command. In the same function I wait for key From
socket and when I receive it I call the interface function Execute() which
intern implements behavior in the main thread Execute Function definition.
I have run into a bump here:
In my main thread run() function I register the key and the function in a
hash map.
public void run()
{
_this = this;
try
{
FunctionDictionary.RegisterFunction(String.valueOf(CONSTANTS.INITIALIZE),
new IFunctionDictionary()
{
public void Execute()
{
_this.m_init();
}
});
this.m_localServerSocket =
newServerSocket(InitializeTeacherJar.getLocalPort());
this.m_localServerSocket.setReuseAddress(true);
this.m_localServerSocket.setSoTimeout(100000);
this.m_localSocket = m_localServerSocket.accept();
while (true)
{
ApplicationLog.log("Flex Listener Thread Started:: Waiting for Server
Socket", true);
if (this.m_localSocket != null)
ApplicationLog.log("Flex Thread:: Flex socket created at port no:", true);
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(this.
m_localSocket.getInputStream()));
line = null;
while ((line = in.readLine()) != null)
{
this.m_command = line;
this.m_commandParameters = this.m_command.split("#");
FunctionDictionary.Execute(this.m_commandParameters[0]);
}
}
catch (Exception e)
{
ApplicationLog.log("Exception Flex Listener Process Command" +
e.getMessage(), true);
}
}
}
catch (Exception e)
{
ApplicationLog.log("Exception Flex Listener Thread: cant create server
socket." + e.getMessage(), true);
}
}
The m_init gets called when I receive the key from socket.
private void m_init()
{
if (_this.m_isInitialized)
return;
else
{
try
{
InitializeTeacherJar.instantiate(_this.m_command.split("#")[1], _this.
baseContext, _this.m_command.split("#")[2]);
_this.m_parent = InitializeTeacherJar.getInstance();
_this.m_parent.setMyFlexServer(_this.m_localServerSocket);
_this.m_parent.setMyFlexSocket(_this.m_localSocket);
_this.m_isInitialized = true;
}
catch (Exception e)
{
//Log it
}
}
}
The mechanism it self is fine, no bugs, no crash. But when I come to the
Ist line of the m_init function the thread crashes abruptly.
Is there something missing...!!
On Tue, Jul 17, 2012 at 5:02 PM, Harsh Vardhan <[email protected]>wrote:
> Thanks Ali.
>
> I am aware of the what the design patterns are, what i needed to know is
> which one hits the spot in my case. Anyways I have gone ahead with
> something that I have figured after some head scratching and will let you
> all know if i succeed.
>
>
>
> On Tue, Jul 17, 2012 at 12:42 PM, Ali Chousein <[email protected]>wrote:
>
>> You cannot extend case statements in your code dynamically, but take a
>> look at the strategy design pattern (
>> http://en.wikipedia.org/wiki/Strategy_pattern). I think that's what you
>> need. Design patterns are not Android specific by the way, they are just a
>> set of best practices in designing software.
>>
>> -------------------------------------------------
>> Ali Chousein
>> https://play.google.com/store/apps/details?id=com.apps.social_nav
>> https://play.google.com/store/apps/details?id=com.apps.weather_buddy
>> http://www.paygol.com/android/implementation
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
>
>
>
> --
> Regards
> Harsh Vardhan
>
>
--
Regards
Harsh Vardhan
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en