@Override public void store(V obj) { File file = getFile(obj.getId()); log.tracef("Storing state to %s", file); try { FileOutputStream outputStream = null; try { outputStream = FOSAction.open(file); SimpleDataOutput output = new SimpleDataOutput(Marshalling.createByteOutput(outputStream)); int version = this.passivationManager.getCurrentMarshallingVersion(); output.writeInt(version); MarshallingConfiguration config = this.passivationManager.getMarshallingConfiguration(version); Marshaller marshaller = this.marshallerFactory.createMarshaller(config); marshaller.start(output); try { marshaller.writeObject(obj); marshaller.finish(); counter.incrementAndGet(); } finally { marshaller.close(); } } finally { safeClose(outputStream); } } catch (IOException e) { throw EjbMessages.MESSAGES.passivationFailed(e, obj.getId()); } }
@Test public void testFragmentedUnmarshalling() throws IOException { MarshallerFactory marshallerFactory = createMarshallerFactory(); MarshallingConfiguration configuration = createMarshallingConfig(); DecoderEmbedder<Object> decoder = new DecoderEmbedder<Object>(createDecoder(marshallerFactory, configuration, 0)); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Marshaller marshaller = marshallerFactory.createMarshaller(configuration); marshaller.start(Marshalling.createByteOutput(bout)); marshaller.writeObject(testObject); marshaller.finish(); marshaller.close(); byte[] testBytes = bout.toByteArray(); ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(testBytes); ChannelBuffer slice = buffer.readSlice(2); decoder.offer(slice); decoder.offer(buffer); assertTrue(decoder.finish()); String unmarshalled = (String) decoder.poll(); Assert.assertEquals(testObject, unmarshalled); Assert.assertNull(decoder.poll()); }
@Override public boolean execute(ManagedServer server) throws Exception { assert Thread.holdsLock(ManagedServer.this); // Call under lock // Get the standalone boot updates final List<ModelNode> bootUpdates = Collections.emptyList(); // bootConfiguration.getBootUpdates(); final Map<String, String> launchProperties = parseLaunchProperties(bootConfiguration.getServerLaunchCommand()); final boolean useSubsystemEndpoint = bootConfiguration.isManagementSubsystemEndpoint(); final ModelNode endpointConfig = bootConfiguration.getSubsystemEndpointConfiguration(); // Send std.in final ServiceActivator hostControllerCommActivator = DomainServerCommunicationServices.create( endpointConfig, managementURI, serverName, serverProcessName, authKey, useSubsystemEndpoint); final ServerStartTask startTask = new ServerStartTask( hostControllerName, serverName, 0, operationID, Collections.<ServiceActivator>singletonList(hostControllerCommActivator), bootUpdates, launchProperties); final Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(CONFIG); final OutputStream os = processControllerClient.sendStdin(serverProcessName); marshaller.start(Marshalling.createByteOutput(os)); marshaller.writeObject(startTask); marshaller.finish(); marshaller.close(); os.close(); return true; }
@Test public void testTooBigObject() throws IOException { MarshallerFactory marshallerFactory = createMarshallerFactory(); MarshallingConfiguration configuration = createMarshallingConfig(); MarshallingDecoder mDecoder = createDecoder(marshallerFactory, configuration, 1); DecoderEmbedder<Object> decoder = new DecoderEmbedder<Object>(mDecoder); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Marshaller marshaller = marshallerFactory.createMarshaller(configuration); marshaller.start(Marshalling.createByteOutput(bout)); marshaller.writeObject(testObject); marshaller.finish(); marshaller.close(); byte[] testBytes = bout.toByteArray(); try { decoder.offer(ChannelBuffers.wrappedBuffer(testBytes)); fail(); } catch (CodecEmbedderException e) { assertEquals(TooLongFrameException.class, e.getCause().getClass()); } }