Package org.jboss.web.tomcat.service.session.distributedcache.spi

Examples of org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata


   }

   private int executeReInsert(OutgoingSessionGranularitySessionData session, byte[] obs, Connection conn)
         throws SQLException, IOException
   {
      DistributableSessionMetadata metadata = session.getMetadata();
      int size = obs.length;
      InputStream in = null;
      if (obs != null)
      {
         ByteArrayInputStream bis = new ByteArrayInputStream(obs);
         in = new BufferedInputStream(bis, size);
      }

      try
      {
         PreparedStatement preparedUpdateSql = prepareStatement(conn, getReInsertSql());
         preparedUpdateSql.setInt(1, session.getVersion());
         preparedUpdateSql.setLong(2, session.getTimestamp());
         preparedUpdateSql.setString(3, metadata.getId());
         preparedUpdateSql.setString(4, metadata.isNew() ? "1" : "0");
         preparedUpdateSql.setInt(5, metadata.getMaxInactiveInterval());
         preparedUpdateSql.setString(6, metadata.isValid() ? "1" : "0");
         preparedUpdateSql.setBinaryStream(7, in, size);
         preparedUpdateSql.setLong(8, metadata.getCreationTime());

         // Add in the WHERE clause params
         preparedUpdateSql.setString(9, session.getRealId());
         preparedUpdateSql.setString(10, getName());
         int count = preparedUpdateSql.executeUpdate();
View Full Code Here


   }

   private int executeUpdate(OutgoingSessionGranularitySessionData session, byte[] obs, Connection conn)
         throws SQLException, IOException
   {
      DistributableSessionMetadata metadata = session.getMetadata();
      int size = obs == null ? -1 : obs.length;
      InputStream in = null;
      if (obs != null)
      {
         ByteArrayInputStream bis = new ByteArrayInputStream(obs);
         in = new BufferedInputStream(bis, size);
      }

      try
      {
         PreparedStatement preparedUpdateSql = null;
         int idParam = -1; // first parameter in the WHERE clause
         if (metadata != null)
         {
            if (obs != null)
            {
               preparedUpdateSql = prepareStatement(conn, getFullUpdateSql());
               preparedUpdateSql.setBinaryStream(7, in, size);
               idParam = 8;
            }
            else
            {
               preparedUpdateSql = prepareStatement(conn, getMetadataUpdateSql());
               idParam = 7;
            }

            preparedUpdateSql.setString(3, metadata.getId());
            preparedUpdateSql.setString(4, metadata.isNew() ? "1" : "0");
            preparedUpdateSql.setInt(5, metadata.getMaxInactiveInterval());
            preparedUpdateSql.setString(6, metadata.isValid() ? "1" : "0");
         }
         else if (obs != null)
         {
            preparedUpdateSql = prepareStatement(conn, getAttributeUpdateSql());
            preparedUpdateSql.setBinaryStream(3, in, size);
View Full Code Here

         {
            String realId = entry.getKey();
            String owner = entry.getValue();

            long ts = -1;
            DistributableSessionMetadata md = null;
            try
            {
               IncomingDistributableSessionData sessionData = proxy_.getSessionData(realId, owner, false);
               if (sessionData == null)
               {
                  log_.debug("Metadata unavailable for unloaded session " + realId);
                  continue;
               }
               ts = sessionData.getTimestamp();
               md = sessionData.getMetadata();
            }
            catch (Exception e)
            {
               // most likely a lock conflict if the session is being updated remotely;
               // ignore it and use default values for timstamp and maxInactive
               log_.debug("Problem reading metadata for session " + realId + " -- " + e.toString(), e);              
            }
           
            long lastMod = ts == -1 ? System.currentTimeMillis() : ts;
            int maxLife = md == null ? getMaxInactiveInterval() : md.getMaxInactiveInterval();
           
            OwnedSessionUpdate osu = new OwnedSessionUpdate(owner, lastMod, maxLife, false);
            unloadedSessions_.put(realId, osu);
         }
        
View Full Code Here

   @Override
   protected OutgoingSessionGranularitySessionData getOutgoingSessionData()
   {
      Map<String, Object> attrs = isSessionAttributeMapDirty() ? getSessionAttributeMap() : null;
      DistributableSessionMetadata metadata = isSessionMetadataDirty() ? getSessionMetadata() : null;
      Long timestamp = attrs != null || metadata != null || getMustReplicateTimestamp() ? Long.valueOf(getSessionTimestamp()) : null;
      return new OutgoingData(getRealId(), getVersion(), timestamp, metadata, attrs);
   }
View Full Code Here

   {
      testee.start();
     
      int existing = testee.getSize();
     
      DistributableSessionMetadata md = new DistributableSessionMetadata();
      String id = nextId();
      md.setId(id + ".full");
      md.setCreationTime(System.currentTimeMillis());
      md.setNew(true);
      md.setValid(true);
      md.setMaxInactiveInterval(30000);
      Long ts = Long.valueOf(md.getCreationTime() + 1);
      Map<String, Object> attrs = new HashMap<String, Object>();
      attrs.put("key", "value");
      OutgoingSessionGranularitySessionData sessionData = new MockOutgoingSessionData(id, 0, ts, md, attrs);
      testee.storeSessionData(sessionData);
     
      assertEquals(Integer.valueOf(0), testee.getSessionVersion(id));
     
      md = new DistributableSessionMetadata();
      String id2 = nextId();
      md.setId(id2 + ".full");
      md.setCreationTime(System.currentTimeMillis());
      md.setNew(true);
      md.setValid(true);
      md.setMaxInactiveInterval(30000);
      ts = Long.valueOf(md.getCreationTime() + 1);
      attrs = new HashMap<String, Object>();
      attrs.put("key", "value");
      sessionData = new MockOutgoingSessionData(id2, 0, ts, md, attrs);
      testee.storeSessionData(sessionData);
     
View Full Code Here

    * Test method for {@link org.jboss.web.tomcat.service.session.persistent.RDBMSStoreBase#getSessionIds()}.
    */
   public void testGetSessionIds()
   {
      testee.start();
      DistributableSessionMetadata md = new DistributableSessionMetadata();
      String id = nextId();
      md.setId(id + ".full");
      md.setCreationTime(System.currentTimeMillis());
      md.setNew(true);
      md.setValid(true);
      md.setMaxInactiveInterval(30000);
      Long ts = Long.valueOf(md.getCreationTime() + 1);
      Map<String, Object> attrs = new HashMap<String, Object>();
      attrs.put("key", "value");
      OutgoingSessionGranularitySessionData sessionData = new MockOutgoingSessionData(id, 0, ts, md, attrs);
      testee.storeSessionData(sessionData);
     
      md = new DistributableSessionMetadata();
      String id2 = nextId();
      md.setId(id2 + ".full");
      md.setCreationTime(System.currentTimeMillis());
      md.setNew(true);
      md.setValid(true);
      md.setMaxInactiveInterval(30000);
      ts = Long.valueOf(md.getCreationTime() + 1);
      attrs = new HashMap<String, Object>();
      attrs.put("key", "value");
      sessionData = new MockOutgoingSessionData(id2, 0, ts, md, attrs);
      testee.storeSessionData(sessionData);
     
View Full Code Here

    * Test method for {@link org.jboss.web.tomcat.service.session.persistent.RDBMSStoreBase#getSessionData(java.lang.String, boolean)}.
    */
   public void testGetSessionData()
   {
      testee.start();
      DistributableSessionMetadata md = new DistributableSessionMetadata();
      String id = nextId();
      md.setId(id + ".full");
      md.setCreationTime(System.currentTimeMillis());
      md.setNew(true);
      md.setValid(true);
      md.setMaxInactiveInterval(30000);
      Long ts = Long.valueOf(md.getCreationTime() + 1);
      Map<String, Object> attrs = new HashMap<String, Object>();
      attrs.put("key", "value");
      OutgoingSessionGranularitySessionData sessionData = new MockOutgoingSessionData(id, 0, ts, md, attrs);
      testee.storeSessionData(sessionData);
     
      IncomingDistributableSessionData incoming = testee.getSessionData(id, true);
      assertEquals(0, incoming.getVersion());
      assertEquals(md.getCreationTime() + 1, incoming.getTimestamp());
      assertEquals(md.getId(), incoming.getMetadata().getId());
      assertEquals(md.getCreationTime(), incoming.getMetadata().getCreationTime());
      assertEquals(md.isNew(), incoming.getMetadata().isNew());
      assertEquals(md.isValid(), incoming.getMetadata().isValid());
      assertEquals(md.getMaxInactiveInterval(), incoming.getMetadata().getMaxInactiveInterval());
      assertTrue(incoming.providesSessionAttributes());
      assertEquals(attrs, incoming.getSessionAttributes());
     
      incoming = testee.getSessionData(id, false);
      assertEquals(0, incoming.getVersion());
      assertEquals(md.getCreationTime() + 1, incoming.getTimestamp());
      assertEquals(md.getId(), incoming.getMetadata().getId());
      assertEquals(md.getCreationTime(), incoming.getMetadata().getCreationTime());
      assertEquals(md.isNew(), incoming.getMetadata().isNew());
      assertEquals(md.isValid(), incoming.getMetadata().isValid());
      assertEquals(md.getMaxInactiveInterval(), incoming.getMetadata().getMaxInactiveInterval());
      assertFalse(incoming.providesSessionAttributes());
   }
View Full Code Here

     
      testee.clear();
     
      int existing = testee.getSize();
     
      DistributableSessionMetadata md = new DistributableSessionMetadata();
      String id = nextId();
      md.setId(id + ".full");
      md.setCreationTime(System.currentTimeMillis());
      md.setNew(true);
      md.setValid(true);
      md.setMaxInactiveInterval(30000);
      Long ts = Long.valueOf(md.getCreationTime() + 1);
      Map<String, Object> attrs = new HashMap<String, Object>();
      attrs.put("key", "value");
      OutgoingSessionGranularitySessionData sessionData = new MockOutgoingSessionData(id, 0, ts, md, attrs);
      testee.storeSessionData(sessionData);
     
View Full Code Here

    * Test method for {@link org.jboss.web.tomcat.service.session.persistent.RDBMSStoreBase#storeSessionData(org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData)}.
    */
   public void testInsertSessionData()
   {
      testee.start();
      DistributableSessionMetadata md = new DistributableSessionMetadata();
      String id = nextId();
      md.setId(id + ".full");
      md.setCreationTime(System.currentTimeMillis());
      md.setNew(true);
      md.setValid(true);
      md.setMaxInactiveInterval(30000);
      Long ts = Long.valueOf(md.getCreationTime() + 1);
      Map<String, Object> attrs = new HashMap<String, Object>();
      attrs.put("key", "value");
      OutgoingSessionGranularitySessionData sessionData = new MockOutgoingSessionData(id, 0, ts, md, attrs);
      testee.storeSessionData(sessionData);
     
      IncomingDistributableSessionData incoming = testee.getSessionData(id, true);
      assertEquals(0, incoming.getVersion());
      assertEquals(md.getCreationTime() + 1, incoming.getTimestamp());
      assertEquals(md.getId(), incoming.getMetadata().getId());
      assertEquals(md.getCreationTime(), incoming.getMetadata().getCreationTime());
      assertEquals(md.isNew(), incoming.getMetadata().isNew());
      assertEquals(md.isValid(), incoming.getMetadata().isValid());
      assertEquals(md.getMaxInactiveInterval(), incoming.getMetadata().getMaxInactiveInterval());
      assertTrue(incoming.providesSessionAttributes());
      assertEquals(attrs, incoming.getSessionAttributes());
   }
View Full Code Here

    * Test method for {@link org.jboss.web.tomcat.service.session.persistent.RDBMSStoreBase#storeSessionData(org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData)}.
    */
   public void testInsertSessionDataNullAttributes()
   {
      testee.start();
      DistributableSessionMetadata md = new DistributableSessionMetadata();
      String id = nextId();
      md.setId(id + ".full");
      md.setCreationTime(System.currentTimeMillis());
      md.setNew(true);
      md.setValid(true);
      md.setMaxInactiveInterval(30000);
      Long ts = Long.valueOf(md.getCreationTime() + 1);
      Map<String, Object> attrs = null;
      OutgoingSessionGranularitySessionData sessionData = new MockOutgoingSessionData(id, 0, ts, md, attrs);
      testee.storeSessionData(sessionData);
     
      IncomingDistributableSessionData incoming = testee.getSessionData(id, true);
      assertEquals(0, incoming.getVersion());
      assertEquals(md.getCreationTime() + 1, incoming.getTimestamp());
      assertEquals(md.getId(), incoming.getMetadata().getId());
      assertEquals(md.getCreationTime(), incoming.getMetadata().getCreationTime());
      assertEquals(md.isNew(), incoming.getMetadata().isNew());
      assertEquals(md.isValid(), incoming.getMetadata().isValid());
      assertEquals(md.getMaxInactiveInterval(), incoming.getMetadata().getMaxInactiveInterval());
      Map<String, Object> map = incoming.getSessionAttributes();
      assertNotNull(map);
      assertEquals(0, map.size());
   }
View Full Code Here

TOP

Related Classes of org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.