Here I make an example.
==========================================
Class B{
public B(){
}
public void execute(){
//some code
}
}
==========================================
public class A extends SFSExtension {
private B b;
@Override
public void init() {
b = new B();
}
}
==========================================
The method execute() of class B is not called in the init().It's called somewhere.
And then I modify some code in the execute().
When the SFSExtension is auto-reload,the new code of execute() does not work.
How to reload the class method and make it work?
p.s. Class B and A is in the same JAR file.
Some problems about reload
Re: Some problems about reload
What you're doing seems correct.
When you sai that B.execute() is called somewhere else, you mean from another class that is also contained in the same Jar file?
Also :
1) are sure there are no errors when reloading the Extension?
2) you're not deploying your Extension under __lib__/ right?
thanks
When you sai that B.execute() is called somewhere else, you mean from another class that is also contained in the same Jar file?
Also :
1) are sure there are no errors when reloading the Extension?
2) you're not deploying your Extension under __lib__/ right?
thanks
Re: Some problems about reload
Lapo wrote:What you're doing seems correct.
When you sai that B.execute() is called somewhere else, you mean from another class that is also contained in the same Jar file?
Also :
1) are sure there are no errors when reloading the Extension?
2) you're not deploying your Extension under __lib__/ right?
thanks
1)Without any errors when reloading the Extension.
2)Another class is also contained in the Extension Jar file with Class A & B.They are put under /extensions/ProjectName/
At the beginning,I tried to set the method execute() to static(When I need to called it,I called B.execute() directly),but however,it does not work after I modify some code in the method.
And then,I changed it to new the object,like the example I mentioned above.It still does not work.
Also I print the hash code of the object b in the A.init(),and compare them.One is b.hashCode() when start up the server,another one is b.hashCode() when reload the Jar file.
================================
@Override
public void init() {
print(b.hashCode());
}
================================
The result showed that they are not same.So I think that,it is a new object indeed.
But,I also print the hash code in the execute() in the same time,just like this:
================================
public void execute(){
print(hashCode());
}
================================
The result showed that it is same with the one when start up the server.It means the method is not reloaded.
So I need some help to tell me how to make it work,thx.
Re: Some problems about reload
We are not able to reproduce this problem.
What version of SFS2X are you using?
Thanks
p.s. = also can you show me the code of your class with the execute method?
What version of SFS2X are you using?
Thanks
p.s. = also can you show me the code of your class with the execute method?
Re: Some problems about reload
Lapo wrote:We are not able to reproduce this problem.
What version of SFS2X are you using?
Thanks
p.s. = also can you show me the code of your class with the execute method?
SFS2X version is 2.8.5
Code: Select all
public class Master {
public Master() {
}
public void execute() {
int[] arr = new int[] { 3, 4, 5, 7, 6, 7, 7 };
// int[] arr = new int[] { 3, 4, 5 };
System.out.println(Arrays.toString(arr));
}
}
Code: Select all
public class DemoSFSExtension extends SFSExtension {
public static DemoSFSExtension instance;
private Master master;
@Override
public void init() {
// TODO Auto-generated method stub
instance = this;
master = new Master();
addEventHandler(SFSEventType.SERVER_READY, ServerReady.class);
}
public Master getMaster() {
return master;
}
}
Code: Select all
public class ServerReady extends BaseServerEventHandler {
@Override
public void handleServerEvent(ISFSEvent arg0) throws SFSException {
SmartFoxServer.getInstance().getTaskScheduler().scheduleAtFixedRate(new DemoRunnable(), 0, 1, TimeUnit.SECONDS);
}
}
Code: Select all
public class DemoRunnable implements Runnable {
@Override
public void run() {
System.out.println("Master hashcode:" + DemoSFSExtension.instance.getMaster().hashCode());
DemoSFSExtension.instance.getMaster().execute();
}
}
if I change the arr in the Master.execute(),and update to reload,it does not print the new arr.
Re: Some problems about reload
Are you manually shutting down the scheduled task in the destroy() method in your Extension?
From the code you have posted it doesn't look like you do, because you don't keep a reference to the created task.
See here for more details:
http://smartfoxserver.com/blog/how-to-s ... extension/
Let me know.
From the code you have posted it doesn't look like you do, because you don't keep a reference to the created task.
See here for more details:
http://smartfoxserver.com/blog/how-to-s ... extension/
Let me know.
Re: Some problems about reload
Lapo wrote:Are you manually shutting down the scheduled task in the destroy() method in your Extension?
From the code you have posted it doesn't look like you do, because you don't keep a reference to the created task.
See here for more details:
http://smartfoxserver.com/blog/how-to-s ... extension/
Let me know.
I modify my code according to the blog and test it,that's ok.Thanks so much.
But I found some exception will appear by accidentally.
Code: Select all
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.smartfoxserver.v2.exceptions.SFSExtensionException
Message: Class not found: com.test.CenterExtension
Description: An error occurred while reloading extension: CenterServer in { Zone: CenterServer }
The new extension might not function properly.
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createJavaExtension(
SFSExtensionManager.java:357)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSE
xtensionManager.java:259)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.reloadExtension(SFSE
xtensionManager.java:529)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager$ExtensionFileChangeL
istener.fileChanged(SFSExtensionManager.java:110)
org.apache.commons.vfs.events.ChangedEvent.notify(ChangedEvent.java:34)
org.apache.commons.vfs.provider.AbstractFileSystem.fireEvent(AbstractFileSystem.
java:519)
org.apache.commons.vfs.provider.AbstractFileSystem.fireFileChanged(AbstractFileS
ystem.java:487)
org.apache.commons.vfs.impl.DefaultFileMonitor$FileMonitorAgent.check(DefaultFil
eMonitor.java:647)
org.apache.commons.vfs.impl.DefaultFileMonitor$FileMonitorAgent.access$200(Defau
ltFileMonitor.java:418)
org.apache.commons.vfs.impl.DefaultFileMonitor.run(DefaultFileMonitor.java:373)
java.lang.Thread.run(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I have catch the exception in the Runnable.run(),but It seems that it's no effect on my code.
Re: Some problems about reload
There is a problem in your Extension:
a class called com.test.CenterExtension is not found in the jar file you have provided.
cheers
Code: Select all
Exception: com.smartfoxserver.v2.exceptions.SFSExtensionException
Message: Class not found: com.test.CenterExtension
Description: An error occurred while reloading extension: CenterServer in { Zone: CenterServer }
The new extension might not function properly.
a class called com.test.CenterExtension is not found in the jar file you have provided.
cheers
Who is online
Users browsing this forum: No registered users and 80 guests