Skip to content

Commit

Permalink
IGNITE-22352 Fix bean creation order (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
shnus authored May 29, 2024
1 parent 51403ae commit 64aade8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.apache.ignite.Ignite;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import jakarta.annotation.PostConstruct;
import org.apache.ignite.Ignite;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.client.IgniteClient;
Expand Down Expand Up @@ -68,9 +67,6 @@ public class IgniteHttpSessionConfiguration extends SpringHttpSessionConfigurati
/** */
private SaveMode saveMode = SaveMode.ON_SET_ATTRIBUTE;

/** */
private SessionProxy sessions;

/** */
private ApplicationEventPublisher applicationEvtPublisher;

Expand All @@ -80,17 +76,6 @@ public class IgniteHttpSessionConfiguration extends SpringHttpSessionConfigurati
/** */
private List<SessionRepositoryCustomizer<IgniteIndexedSessionRepository>> sesRepoCustomizers;

/** */
private Object connObj;

/**
* @return Session repository.
*/
@Bean
public SessionRepository<?> sessionRepository() {
return createIgniteIndexedSessionRepository();
}

/**
* @param maxInactiveIntervalInSeconds Maximum inactive interval in sec.
*/
Expand Down Expand Up @@ -119,36 +104,6 @@ public void setSaveMode(SaveMode saveMode) {
this.saveMode = saveMode;
}

/**
* @param springSesIgnite Ignite session.
* @param ignite Ignite instance provider.
* @param cli Ignite client instance provider.
*/
@Autowired
public void setSessions(
@SpringSessionIgnite ObjectProvider<Object> springSesIgnite,
ObjectProvider<Ignite> ignite,
ObjectProvider<IgniteClient> cli
) {
Object connObj = springSesIgnite.getIfAvailable();

if (connObj == null)
connObj = ignite.getIfAvailable();

if (connObj == null)
connObj = cli.getIfAvailable();

this.connObj = connObj;
}

/**
* Init sessions.
*/
@PostConstruct
public void initSessions() {
this.sessions = createSessionProxy(this.connObj);
}

/**
* @param applicationEvtPublisher Application event publisher.
*/
Expand Down Expand Up @@ -189,8 +144,28 @@ public void setSessionRepositoryCustomizer(
this.saveMode = attrs.getEnum("saveMode");
}

/** */
private SessionProxy createSessionProxy(Object connObj) {
/**
* Session cache proxy.
*
* @param springSesIgnite Ignite session.
* @param igniteProvider Ignite instance provider.
* @param igniteClientProvider Ignite client instance provider.
* @return Session cache proxy.
*/
@Bean
public SessionProxy sessionProxy(
@SpringSessionIgnite ObjectProvider<Object> springSesIgnite,
ObjectProvider<Ignite> igniteProvider,
ObjectProvider<IgniteClient> igniteClientProvider
) {
Object connObj = springSesIgnite.getIfAvailable();

if (connObj == null)
connObj = igniteProvider.getIfAvailable();

if (connObj == null)
connObj = igniteClientProvider.getIfAvailable();

List<SqlFieldsQuery> initQueries = Arrays.asList(
new SqlFieldsQuery("CREATE TABLE IF NOT EXISTS IgniteSession (" +
" id VARCHAR PRIMARY KEY," +
Expand Down Expand Up @@ -224,9 +199,15 @@ private SessionProxy createSessionProxy(Object connObj) {
"Object " + connObj + " can not be used to connect to the Ignite cluster.");
}

/** */
private IgniteIndexedSessionRepository createIgniteIndexedSessionRepository() {
IgniteIndexedSessionRepository sesRepo = new IgniteIndexedSessionRepository(this.sessions);
/**
* Session repository bean.
*
* @param sesProxy Session cache proxy.
* @return Session repository.
*/
@Bean
public SessionRepository<?> sessionRepository(SessionProxy sesProxy) {
IgniteIndexedSessionRepository sesRepo = new IgniteIndexedSessionRepository(sesProxy);
sesRepo.setApplicationEventPublisher(this.applicationEvtPublisher);
if (this.idxResolver != null)
sesRepo.setIndexResolver(this.idxResolver);
Expand Down

0 comments on commit 64aade8

Please sign in to comment.