JavaSpaceを使用する必要のあるチャットシステムを作成しようとしています。自動通知を機能させようとしている場合を除いて、ほとんどの場合、これは機能しています。これにより、エントリが追加されたときにスペースからリストに新しいエントリが追加されたときにリストを更新できます。java.lang.ExceptionInInitializerErrorが発生すると、これが問題になります。完全なトレース出力は次のとおりです。
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at com.sun.jini.thread.GetThreadPoolAction.<clinit>(GetThreadPoolAction.java:52)
at net.jini.jeri.tcp.TcpServerEndpoint.<clinit>(TcpServerEndpoint.java:117)
at com.chat.client.gui.Topics.<init>(Topics.java:129)
at com.chat.client.gui.Main.actionPerformed(Main.java:114)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6382)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6147)
at java.awt.Container.processEvent(Container.java:2083)
at java.awt.Component.dispatchEventImpl(Component.java:4744)
at java.awt.Container.dispatchEventImpl(Container.java:2141)
at java.awt.Component.dispatchEvent(Component.java:4572)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
at java.awt.Container.dispatchEventImpl(Container.java:2127)
at java.awt.Window.dispatchEventImpl(Window.java:2489)
at java.awt.Component.dispatchEvent(Component.java:4572)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:704)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:663)
at java.awt.EventQueue$2.run(EventQueue.java:661)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:677)
at java.awt.EventQueue$3.run(EventQueue.java:675)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:674)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:549)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkAccess(SecurityManager.java:712)
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:299)
at java.lang.ThreadGroup.getParent(ThreadGroup.java:150)
at com.sun.jini.thread.NewThreadAction$1.run(NewThreadAction.java:54)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.jini.thread.NewThreadAction.<clinit>(NewThreadAction.java:49)
... 40 more
私が使用しているコードは以下のとおりです
package com.chat.client.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
import net.jini.core.entry.UnusableEntryException;
import net.jini.core.lease.Lease;
import net.jini.core.transaction.TransactionException;
import net.jini.space.JavaSpace;
import com.chat.client.backend.SpaceUtils;
import com.chat.client.backend.Topic;
import com.chat.client.backend.TopicList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import net.jini.core.event.RemoteEvent;
import net.jini.core.event.RemoteEventListener
import java.rmi.server.*;
import java.rmi.RemoteException;
import net.jini.core.event.*;
import net.jini.export.Exporter;
import net.jini.jeri.BasicILFactory;
import net.jini.jeri.BasicJeriExporter;
import net.jini.jeri.tcp.TcpServerEndpoint;
import java.rmi.RMISecurityManager;
public class Topics extends javax.swing.JFrame implements ActionListener, RemoteEventListener {
private JList topicList;
private JScrollPane jScrollPane1;
private JButton exitButton;
private JButton closeButton;
private JButton joinTopic;
private JButton addButton;
private JLabel jLabel2;
private JLabel jLabel1;
private JTextField topicNameTextField;
/*
* user added variables
*/
private static JavaSpace space;
private String ownersName;
private String[] theTopics;
private boolean isFirstTimeStart = true;
private TopicList theList = null;
private TopicList template_list = null;
private ArrayList<String> topics;
private DefaultListModel topicListModel;
private RemoteEventListener theStub;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) throws RemoteException{
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Topics inst = new Topics();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public Topics() {
super();
space = SpaceUtils.getSpace();
if (space == null){
System.err.println("Failed to find the javaspace");
System.exit(1);
}
try{
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
Exporter myDefaultExporter =
new BasicJeriExporter(TcpServerEndpoint.getInstance(0),
new BasicILFactory(), false, true);
} catch(Exception ex) {
}
initGUI();
}
public Topics(String s) {
super();
space = SpaceUtils.getSpace();
if (space == null){
System.err.println("Failed to find the javaspace");
System.exit(1);
}
try {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
/*****The issue seems to arise here when instantiating the Exporter **********/
// create the exporter
Exporter myDefaultExporter =
new BasicJeriExporter(TcpServerEndpoint.getInstance(0),
new BasicILFactory(), false, true);
// register this as a remote object
// and get a reference to the 'stub'
theStub = (RemoteEventListener) myDefaultExporter.export(this);
// add the listener
space.notify(template_list, null, this.theStub, Lease.FOREVER, null);
ownersName = s; when using
topics = new ArrayList<String>();
topicListModel = new DefaultListModel();
template_list = null;
template_list = new TopicList();
System.out.println("trying to get the list from the space");
theList = null;
theList = (TopicList) space.take(template_list, null, Long.MAX_VALUE);
System.out.println("Got the list");
if(!theList.topics.isEmpty() && theList.topicListName.equals("GZSpace")) {
System.out.println("list is not empty");
for(int i = 0; i < theList.topics.size(); i++) {
topicListModel.addElement(theList.topics.get(i));
}
space.write(theList, null, Lease.FOREVER);
} else {
space.write(theList, null, Lease.FOREVER);
}
} catch (UnusableEntryException ex) {
Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
} catch (TransactionException ex) {
Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
}
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jScrollPane1 = new JScrollPane();
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(230, 43, 142, 170);
{
topicList = new JList(topicListModel);
jScrollPane1.setViewportView(topicList);
topicList.setModel(topicListModel);
topicList.setBounds(230, 43, 142, 170);
}
}
{
topicNameTextField = new JTextField();
getContentPane().add(topicNameTextField);
topicNameTextField.setBounds(80, 43, 145, 23);
}
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("To create a topic, enter the name below and click add");
jLabel1.setBounds(12, 15, 355, 16);
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2);
jLabel2.setText("Topic Name:");
jLabel2.setBounds(12, 46, 68, 16);
}
{
addButton = new JButton();
getContentPane().add(addButton);
addButton.setText("Add New " +
"Topic");
addButton.setBounds(12, 88, 213, 23);
addButton.addActionListener(this);
}
{
joinTopic = new JButton();
getContentPane().add(joinTopic);
joinTopic.setText("Join Existing Topic");
joinTopic.setBounds(12, 122, 213, 23);
joinTopic.addActionListener(this);
}
{
closeButton = new JButton();
getContentPane().add(closeButton);
closeButton.setText("Close ");
closeButton.setBounds(12, 156, 213, 23);
closeButton.addActionListener(this);
}
{
exitButton = new JButton();
getContentPane().add(exitButton);
exitButton.setText("Exit Chat System");
exitButton.setBounds(12, 190, 213, 23);
exitButton.addActionListener(this);
}
pack();
this.setSize(400, 269);
} catch (Exception e) {
//add your error handling code here
e.printStackTrace();
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == addButton) {
try {
theList = null;
template_list = null;
theList = (TopicList) space.take(template_list, null, Long.MAX_VALUE);
if(!theList.topics.isEmpty() && theList.topicListName.equals("GZSpace")) {
theList.topics.add(topicNameTextField.getText());
topicListModel.addElement(topicNameTextField.getText());
topicNameTextField.setText("");
space.write(theList, null, Lease.FOREVER);
} else {
space.write(theList, null, Lease.FOREVER);
}
} catch (UnusableEntryException ex) {
Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
} catch (TransactionException ex) {
Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
}
}
if(e.getSource() == joinTopic) {
}
if(e.getSource() == closeButton) {
Main main = new Main();
main.setLocationRelativeTo(null);
main.setVisible(true);
dispose();
}
if(e.getSource() == exitButton) {
dispose();
}
}
public void notify(RemoteEvent ev) {
// this is the method called when we are notified
// of an object of interest
TopicList template = new TopicList();
try {
TopicList theList = (TopicList)space.take(template, null, Long.MAX_VALUE);
for(int i = 0; i < theList.topics.size(); i++) {
topicListModel.addElement(theList.topics.get(i));
}
} catch (Exception e) {
e.printStackTrace();
}
// that's all we need to do in this demo so we can quit...
System.exit(0);
}
}
どんな助けでもありがたいことに受け取られるでしょう。