@Override protected void setUp() throws Exception { tmp = IO.getFile("generated/tmp"); tmp.mkdirs(); IO.copy(IO.getFile("testdata/ws"), tmp); workspace = Workspace.getWorkspace(tmp); workspace.refresh(); InfoRepository repo = workspace.getPlugin(InfoRepository.class); t1 = create("bsn-1", new Version(1, 0, 0)); t2 = create("bsn-2", new Version(1, 0, 0)); repo.put(new FileInputStream(t1), null); repo.put(new FileInputStream(t2), null); t1 = repo.get("bsn-1", new Version(1, 0, 0), null); t2 = repo.get("bsn-2", new Version(1, 0, 0), null); repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null); workspace.getPlugins().add(repo); File storage = IO.getFile("generated/storage-1"); storage.mkdirs(); configuration = new HashMap<String, Object>(); configuration.put( Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath()); configuration.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2"); framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration); framework.init(); framework.start(); context = framework.getBundleContext(); location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString(); agent = context.installBundle(location); agent.start(); thread = new Thread() { @Override public void run() { try { Main.main( new String[] { "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et" }); } catch (Exception e) { e.printStackTrace(); } } }; thread.setDaemon(true); thread.start(); super.setUp(); }
public long openUdpSocket(InetSocketAddress address) throws IOException { // TODO, don't throw an exception out of here. DatagramChannel dg = DatagramChannel.open(); dg.configureBlocking(false); dg.socket().bind(address); long b = createBinding(); EventableChannel ec = new EventableDatagramChannel(dg, b, mySelector); dg.register(mySelector, SelectionKey.OP_READ, ec); Connections.put(b, ec); return b; }
/** Fill Tab and Field arrays */ private void fillTabsFieldsAndInitFieldsAndCreateDependencyRelations(UIWindow win, int windowNO) { ArrayList<UITab> tabs = win.getTabs(); for (int j = 0; j < tabs.size(); j++) { UITab winTab = tabs.get(j); Integer tabKey = Integer.valueOf(winTab.getAD_Tab_ID()); Integer ReferencetabKey = Integer.valueOf(winTab.getReferenced_Tab_ID()); m_tabs.put(tabKey, winTab); m_referencetabs.put(ReferencetabKey, winTab); // ArrayList<UIField> fields = winTab.getFields(); for (int k = 0; k < fields.size(); k++) { UIField field = fields.get(k); field.initialize(m_context, windowNO); Integer fieldKey = Integer.valueOf(field.getAD_Field_ID()); // set the correct value if (field.isLookup()) field.getLookup().setContext(m_context, windowNO); m_fields.put(fieldKey, field); } winTab.createDependencyRelations(); } } // fillTabsFields
public boolean startProxy(long from, long to) { // lazy init for proxy support check quickly in isReadable if (ProxyConnections == null) { ProxyConnections = new HashMap<Long, EventableChannel>(); } EventableChannel target = Connections.get(to); if (target != null) { ProxyConnections.put(from, target); return true; } else { return false; } }
public long attachChannel(SocketChannel sc, boolean watch_mode) { long b = createBinding(); EventableSocketChannel ec = new EventableSocketChannel(sc, b, mySelector); ec.setAttached(); if (watch_mode) ec.setWatchOnly(); Connections.put(b, ec); NewConnections.add(b); return b; }
public long startTcpServer(SocketAddress sa) throws EmReactorException { try { ServerSocketChannel server = ServerSocketChannel.open(); server.configureBlocking(false); server.socket().bind(sa); long s = createBinding(); Acceptors.put(s, server); server.register(mySelector, SelectionKey.OP_ACCEPT, s); return s; } catch (IOException e) { throw new EmReactorException("unable to open socket acceptor: " + e.toString()); } }
/** * Get Field * * @param AD_Field_ID id * @param windowNo relative windowNo * @return field or null */ public UIField getField(int AD_Field_ID, int windowNo) { Integer key = Integer.valueOf(AD_Field_ID); UIField field = m_fields.get(key); if (field == null) { UIFieldVOFactory fieldFactory = new UIFieldVOFactory(); UIFieldVO vo = fieldFactory.get(m_context, AD_Field_ID); // m_context.setSOTrx(windowNo, isSOTrx); if (vo != null) { field = new UIField(vo); field.initialize(m_context, windowNo); log.warning("Loaded directly: " + field); // SOTrx may not // be correct m_fields.put(key, field); // save in cache } } // create new return field; } // getField
void isAcceptable(SelectionKey k) { ServerSocketChannel ss = (ServerSocketChannel) k.channel(); SocketChannel sn; long b; for (int n = 0; n < 10; n++) { try { sn = ss.accept(); if (sn == null) break; } catch (IOException e) { e.printStackTrace(); k.cancel(); ServerSocketChannel server = Acceptors.remove(k.attachment()); if (server != null) try { server.close(); } catch (IOException ex) { } ; break; } try { sn.configureBlocking(false); } catch (IOException e) { e.printStackTrace(); continue; } b = createBinding(); EventableSocketChannel ec = new EventableSocketChannel(sn, b, mySelector); Connections.put(b, ec); NewConnections.add(b); eventCallback(((Long) k.attachment()).longValue(), EM_CONNECTION_ACCEPTED, null, b); } }
public long connectTcpServer(String bindAddr, int bindPort, String address, int port) { long b = createBinding(); try { SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); if (bindAddr != null) sc.socket().bind(new InetSocketAddress(bindAddr, bindPort)); EventableSocketChannel ec = new EventableSocketChannel(sc, b, mySelector); if (sc.connect(new InetSocketAddress(address, port))) { // Connection returned immediately. Can happen with localhost connections. // WARNING, this code is untested due to lack of available test conditions. // Ought to be be able to come here from a localhost connection, but that // doesn't happen on Linux. (Maybe on FreeBSD?) // The reason for not handling this until we can test it is that we // really need to return from this function WITHOUT triggering any EM events. // That's because until the user code has seen the signature we generated here, // it won't be able to properly dispatch them. The C++ EM deals with this // by setting pending mode as a flag in ALL eventable descriptors and making // the descriptor select for writable. Then, it can send UNBOUND and // CONNECTION_COMPLETED on the next pass through the loop, because writable will // fire. throw new RuntimeException("immediate-connect unimplemented"); } else { ec.setConnectPending(); Connections.put(b, ec); NewConnections.add(b); } } catch (IOException e) { // Can theoretically come here if a connect failure can be determined immediately. // I don't know how to make that happen for testing purposes. throw new RuntimeException("immediate-connect unimplemented: " + e.toString()); } return b; }
public void putNode(String key, NodeVO node) { m_nodes.put(key, node); }