I have started reading how to use JXTA from Practical JXTA II for an application i want to make. Although the code provided (examples) doesn't work with JXTA 2.7 . More specifically
Tools class of Z_Tools_And_Others doesn't compile since TheRendezVous class doesn't have getConnectedPeers() and getConnectedRendezVous() which exist in 2.6 . Therefor i cant continue since Tools class is used in most of the examples . Anyone familiar with this got any suggestions ? Is it better to use 2.6 for learning purposes and then move to 2.7 ?
Thanks.
Sorry for the late reply: the files for Practical JXTA II are available from here.
I am pretty sure you are trying to use 2.6 code with 2.7. Let me know if you still encounter an issue with the practical jxta II examples.
package Examples.Z_Tools_And_Others;
public class Tools {
public static void popConnectedRendezvous(RendezVousService TheRendezVous, String Name) {
Enumeration<ID> TheList = TheRendezVous.getConnectedRendezVous();
int Count = 0;
while (TheList.hasMoreElements()) {
Count = Count + 1;
PopInformationMessage(Name, "Connected to rendezvous:\n\n"
+ TheList.nextElement().toString());
}
if (Count==0) {
PopInformationMessage(Name, "No rendezvous connected to this rendezvous!");
}
}
TheList isnt working .The method getConnectedRendezVous is removed in 2.7 . The one that is replacing it is returning a List .That creates more errors later . Should i change the code so that it works for a List ?I thought i could use a listIterator to replace .nextElement() Same problem exists with popConnectedPeers(RendezVousService TheRendezVous, String Name) of same class.
Also line 166 in
package Examples.K_Service;
public class _710_Astrology_Service_Example implements Service, Runnable
Result.setCompat(StdPeerGroup.STD_COMPAT);
STD_COMPAT is removed . I replaced it with this :
ModuleImplAdvertisement ad =StdPeerGroup.getDefaultModuleImplAdvertisement();
Result.setCompat(ad.getCompat());
No idea if its good or not..code compiles tho :P
Related
Basically I have started updating a lot of Heroes spells to 1.7.2 and this update broke the .getHealth() and .getMaxHealth(). I am trying to fix it but I do not know how to. If anyone has some advice or samples I will be in debt. I will place some code where I use the .getHealth() method.
this is the link of the error: http://puu.sh/7BrEP.png. It is saying this method is ambigous for that type.
public void tickHero(Hero hero) {
if ( hero.getPlayer().getHealth() - damage > 1) {
addSpellTarget(hero.getPlayer(), plugin.getCharacterManager().getHero(caster));
damageEntity(hero.getPlayer(), caster, damage, DamageCause.MAGIC);
//hero.getPlayer().damage(damage, caster);
}
}
As of 1.7.2, there are two getHealth() and getMaxHealth() methods. This is becaue of the way Bukkit handled Minecraft changing the way entity health is stored in 1.6. You can read more about this here.
If you aren't using any NMS code, you should use the bukkit.jar in your build path as opposed to craftbukkit.jar. This should resolve your issue easily enough.
If you do need NMS code, you need to have both bukkit.jar AND craftbukkit.jar in your build path. Furthermore, you have to have bukkit.jar above craftbukkit.jar in the build path for it to work.
I am trying to use Google Caliper to benchmark some simple code. I am using the examples from their websites. Here's what I've done so far:
Downloaded the Caliper JAR and added it to my Netbeans project
After having difficulties, I downloaded JUnit.jar and hamcrest.jar. Still not working.
Here's my code:
import com.google.caliper.Benchmark;
public class Benchmark1 extends Benchmark {
public void timeNanoTime(int reps) {
for (int i = 0; i < reps; i++) {
System.nanoTime();
}
}
}
I am extending Benchmark because when I try to extend "SimpleBenchmark" like on their website it tells me it cannot find SimpleBenchmark. I then, in my main method, create a new Benchmark1() hoping something will happen. Nothing does. This is the code inside my main class.
Benchmark1 test = new Benchmark1();
test.timeNanoTime(10);
I know this is no doubt a simple error but I cannot, despite much Googling, figure out where I'm going wrong. The code compiles but does not run.
EDIT: I should say I'm running Netbeans on Windows 7 with Caliper 1.0
It's true; the documentation is woefully outdated and incomplete. I'm working on it. In the meantime, here's what will get your benchmark running.
Your main method should delegate to CaliperMain, not directly to the benchmark. Try
public static void main(String[] args) {
CaliperMain.main(Benchmark1.class, args);
}
Windows will be a problem. Particularly, issue 215 will be the biggest blocker.
You could switch over to Perfidix http://perfidix.org/
Perfidix has eclipse Integration and can be used like JUnit.
Another option would be JUnitbenchmarks http://labs.carrotsearch.com/junit-benchmarks.html
It's a really great framework for Junit 4+. It can even build html charts to compare results.
I have to interface a third party COM API into an Java application. So I decided to use Com4j, and so far I've been satisfied, but now I've run into a problem.
After running the tlbgen I have an object called IAddressCollection which according to the original API documentation conforms to the IEnum interface definition. The object provides an iterator() function that returns a java.util.Iterator<Com4jObject>. The object comes from another object called IMessage when I want to find all the addresses for the message. So I would expect the code to work like this:
IAddressCollection adrCol = IMessage.getAddressees();
Iterator<Com4jObject> adrItr = adrCol.iterator();
while(adrItr.hasNext()){
Com4jObject adrC4j = adrItr.next();
// normally here I would handle the queryInterface
// and work with the rest of the API
}
My problem is that when I attempt the adrItr.next() nothing happens, the code stops working but hangs. No exception is thrown and I usually have to kill it through the task manager. So I'm wondering is this a problem that is common with Com4j, or am I handling this wrong, or is it possibly a problem with the API?
Ok, I hate answering my own question but in this case I found the problem. The issue was the underlying API. The IAddressCollection uses a 1 based indexing instead of a 0 based as I would have expected. It didn't provide this information in the API documentation. There is an item function where I can pull the object this way and so I can handle this with
IAddressCollection adrCol = IMessage.getAddressees();
for(int i = 1; i <= adrCol.count(); i++){
IAddress adr = adrCol.item(i);
// IAddress is the actual interface that I wanted and this works
}
So sorry for the annoyance on this.
My objective is to:
Use Firefox to take a series of screendump images and save on the local Filesystem with a reference.
also via my custom extension send a reference to a java program that performs the ftp to a remote server.
This is pretty intimidating
https://developer.mozilla.org/en/JavaScript/Guide/LiveConnect_Overview
Is it possible?
Can you see any potential problems or things Id need to consider?
(I'm aware of file system problems but its for local use only)
Are there any tutorials / references that might be handy?
Ive tried linking to java but hit problems using my own classes Im getting a class not found exception when I try
JS:
var myObj = new Packages.message();
Java file:
public class Message {
private String message;
public Message()
{
this.message = "Hello";
}
public String getMessage()
{
return this.message;
}
}
not using a package java side.
Just trying to run a quick test to see if it is viable and under time pressure from those above so just wanted to see if it was a worthwhile time investment or a dead end
You might consider this Java tutorial instead: http://www.oracle.com/technetwork/java/javase/documentation/liveconnect-docs-349790.html.
What Java version are you using? Is your message class an object inside Java applet?
My scenario is: One step in my jira workflow should have the ability to unschedule a task i.e. set a Fix Version to "None".
I noticed that I was not able to update fix version in a workflow post function - I don't know exactly why, but anyway I did implement a jira plugin to help me solve my problem but I know I'm going against jira structure (even java good coding practices :)). I am not sure if my implementation can cause problems, but indeed it is working in my jira instance 4.1.x.
How I've implemented a plugin to update fix version in a post function, 2 very similar ways:
public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
// Here I create an empty Collection to be the new value of FixVersion (empty because I need no version in Fix Version)
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
MutableIssue issue = this.getIssue(transientVars);
Collection<Version> newFixVersion = new ArrayList<Version>();
issue.setFixVersions(newFixVersion);
issue.store();
}
}
public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
// here I clear the Collection I got from "old" Fix Version and I have to set it again to make it work.
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
MutableIssue issue = this.getIssue(transientVars);
Collection fixVersions = issue.getFixVersions();
fixVersions.clear();
issue.setFixVersions(fixVersions);
issue.store();
}
}
I presume that a real solution should use classes like: ChangeItemBean, ModifiedValue, IssueChangeHolder - taking as example the updateValue methods from CustomFieldImpl (from jira source code, project: jira, package: com.atlassian.jira.issue.fields).
My point of publishing this here is:
Does anyone know how to implement a jira plugin containing a post function to change Fix Version correctly?
If you want to do it properly take a look in the code for
./jira/src/java/com/atlassian/jira/workflow/function/issue/UpdateIssueFieldFunction.java processField()
Postfunctions that take input parameters are not documented yet it seems. Other places to go for code are other open source plugins.
Atlassian has a tutorial on doing just about exactly what you want to do, here:
I do it like in this snippet:
List<GenericValue> genericValueList = issueManager.getIssues(issues);
versionManager.moveIssuesToNewVersion(genericValueList, lastVersion, newVersion);